Giter Site home page Giter Site logo

gspflash's Introduction

gspflash

Introduction

gspFlash is a utility class for managing LED instances.

How to use

Declare an instance of gspFlash with the pin to which your LED is connected.

For instance:

gspFlash myLED(LED_BUILTIN);

Then you can do stuff like:

myLED.turnOn();
myLED.turnOff();
myLED.flashSlow();
myLED.flashFast();

Requirements

  1. Include header file <gspflash.h>
  2. setup code
  3. Add gspflash library dependency into project.

Example

#include <Arduino.h>
#include <gspflash.h>

gspFlash myLED(LED_BUILTIN);
gslFlash myOtherLED(12);

void setup() {
  gspGrouped::register_instance(&myLED);
  gspGrouped::register_instance(&myOtherLED);

  gspFlash::startCheckAll();
  
  myLED.flashFast();
  myOtherLED.turnOn();
}

Advanced usage: Integration with gspstreamresponse and gspswitch

I have created some utility macros which allow you to connect your LED instances directly to input classes such as gspstreamresponse and gspswitch:

For instance:

gspFlash myLED(LED_BUILTIN);
gspStreamResponse mysr("=b",1,GSPFLASH_ONOFF_PARSER(myLED));

is all the aditional code you need to get your onboard LED turning on and off when the gspstreamresponse instance receicves a "0" or "1"

other integration macros:

Use these in place of callback function definitions. Where I have written 'myLED' you will use your own instance of gspFlash that you have declared.

gspstreamresponse:

  • GSPFLASH_ONOFF_PARSER(myLED)
  • GSPFLASH_OFFON_PARSER(myLED)

gspswitch:

  • GSPFLASH_TURNON(myLED)
  • GSPFLASH_TURNOFF(myLED)
  • GSPFLASH_FLASHSLOW(myLED)
  • GSPFLASH_FLASHFAST(myLED)

Integration example

This code expects a simple momentary pushbutton switch on pin 12 and a built-in LED on pin 13. Repeatedly pushing the button will turn the LED on and off. Also, sending =a0 and =a1 via the serial port will turn the LED off and on.

#include <Arduino.h>
#include <gspflash.h>
#include <gspstreamresponse.h>
#include <gspswitch.h>

gspFlash myLED(LED_BUILTIN);

//the last parameter is the "mode" which puts the switch instance into a latching pushbutton mode (mode 1)
//mode 0 is non-latching.
gspSwitch mySwitch(12,GSPFLASH_TURNOFF(myLED),GSPFLASH_TURNON(myLED),1 /*mode*/);

//This integration allows the LED to be controlled from the serial port.
//=a0 to turn off, =a1 to turn on.
gspStreamResponse mySerial("=a",1,GSPFLASH_ONOFF_PARSER(myLED));

void setup() {
  Serial.begin(115200);
  gspGrouped::register_instance(& myLED);
  gspGrouped::register_instance(& mySwitch);
  gspGrouped::register_instance(& mySerial);
  gspStreamResponse::setup(Serial);

  gspFlash::startCheckAll();
}

void loop () {
  gspSwitch::checkAll();
  gspStreamResponse::checkAll();
}

gspflash's People

Contributors

edwar64896 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.