Skip to content

Instantly share code, notes, and snippets.

@kfrancis
Created December 5, 2019 18:28
Show Gist options
  • Save kfrancis/c4c4a26ad51c9e7c27728c3987c4bc28 to your computer and use it in GitHub Desktop.
Save kfrancis/c4c4a26ad51c9e7c27728c3987c4bc28 to your computer and use it in GitHub Desktop.
Working with the toggles
#include "SparkFun_Qwiic_Button.h"
QwiicButton toggle;
uint8_t brightness = 100;
void setup() {
Serial.begin(115200);
Serial.println("Qwiic toggle examples");
Wire.begin(); //Join I2C bus
//check if toggle will acknowledge over I2C
if (toggle.begin() == false) {
Serial.println("Device did not acknowledge! Freezing.");
while (1);
}
Serial.println("Toggle acknowledged.");
toggle.LEDoff();
}
void loop() {
//check if button is pressed, and tell us if it is!
if (toggle.isPressed() == true) {
Serial.println("The toggle is pressed!");
Particle.publish("toggle toggled!",NULL, 60, PRIVATE);
toggle.LEDon(brightness);
while (toggle.isPressed() == true)
delay(10); //wait for user to untoggle
Serial.println("The toggle is not toggled!");
toggle.LEDoff();
}
delay(20); //Don't hammer too hard on the I2C bus
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment