Skip to content

Instantly share code, notes, and snippets.

@krobro
Last active May 4, 2017 19:29
Show Gist options
  • Save krobro/61d5dc95532ad7a511db to your computer and use it in GitHub Desktop.
Save krobro/61d5dc95532ad7a511db to your computer and use it in GitHub Desktop.
//
// PressAButton
//
// Pressing the button causes the LED to light up.
//
// We are using ports S0 and S1 on the Duinobot board
// * The LED device will be plugged into S0,
// * The Button sensor will be plugged into S1.
//
// NOTES:
// - Ports S0-S5 are analog input pins
// - S0 is identical to Arduino A0 and so on (S5=A5)
// - To use these ports as Digital pins add 14
//
#define S0 0+14
#define S1 1+14
int buttonState; // to store the button state
// 1 - means the button is not pressed
// 0 - means the button is pressed
// run once, when the sketch starts
void setup() {
pinMode(S0, OUTPUT); // sets the port S0 as a digital
// output for the LED device
pinMode(S1, INPUT); // Sets the port S1 as a digital
// input for the button sensor
// Setup serial communication ... commented out for now
//Serial.begin(9600);
}
// run over and over again
void loop() {
// get the button state
buttonState = digitalRead(S1);
// Print the state of the button to the Serial Monitor
//Serial.print("The state of button is: ");
//Serial.println(buttonState);
// if the button is pressed light the led
if (buttonState == 1)
{
digitalWrite (S0, LOW);
}
else
{
digitalWrite (S0, HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment