Created
August 26, 2017 18:33
-
-
Save dhood/b8741ac4f17c0f94a763669cc254aea3 to your computer and use it in GitHub Desktop.
push_ifttt_event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Arduino sketch to send switch values over serial when requested. | |
*/ | |
// ------ Configuration settings | |
int inputPin = 2; // input pin used for the switch | |
// ------ | |
int ledPin = 13; // use the onboard LED pin for debugging purposes | |
int inByte = 0; // incoming serial byte | |
// This function is run when the arduino turns on (only once) | |
void setup() | |
{ | |
pinMode(inputPin, INPUT); // initialise input pin mode | |
Serial.begin(9600); // initialise the serial connection at 9600 baud | |
pinMode(ledPin, OUTPUT); // set the LED's pin as an 'output' pin | |
while (!Serial) { | |
; // wait for the connection to initalise | |
} | |
} | |
// This function is run continuously | |
void loop() | |
{ | |
int buttonState = 0; | |
// only send results when requested | |
if (Serial.available() > 0) { // listen for a command over serial | |
// get incoming byte: | |
inByte = Serial.read(); | |
buttonState = digitalRead(inputPin); | |
int switchValue = digitalRead(inputPin); | |
if (buttonState == HIGH) { | |
digitalWrite(ledPin, HIGH); | |
Serial.println("on"); | |
} | |
else { | |
Serial.println("off"); | |
digitalWrite(ledPin, LOW); | |
} | |
// toggle onboard LED to show something received | |
int oldLedValue = digitalRead(ledPin); | |
int newLedValue = !oldLedValue; | |
//digitalWrite(ledPin, newLedValue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment