Skip to content

Instantly share code, notes, and snippets.

@sdbakker
Created March 31, 2014 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdbakker/9903342 to your computer and use it in GitHub Desktop.
Save sdbakker/9903342 to your computer and use it in GitHub Desktop.
WdKA basic arduino workshop Part 2: Light and Switch
/************************************************************/
/* Sample useless machine code */
/* WdKA basic arduino workshop */
/* */
/* Part 2: Light and Switch */
/* Simon de Bakker <simon@simbits.nl> */
/************************************************************/
/* pin definitions (what is connected to which arduino pin) */
#define LED_PIN 12
#define SWITCH_PIN 8
void setup() {
/* set the directions of each pin */
pinMode(LED_PIN, OUTPUT);
pinMode(SWITCH_PIN, INPUT);
/* just a small routine to let us know setup is finished */
/* turn on our LED */
digitalWrite(LED_PIN, HIGH);
/* wait half a second */
delay(500);
/* turn our LED off again */
digitalWrite(LED_PIN, LOW);
}
void loop() {
/* check if the switch is toggled */
if ( digitalRead(SWITCH_PIN) == HIGH ) {
/* A local variable to hold the amount of ms to wait */
int wait_ms;
/* turn the LED on */
digitalWrite(LED_PIN, HIGH);
/* put a random value between 200 and 2000 in wait_ms */
wait_ms = random(10, 500);
/* wait for the amount of ms stored in wait_ms */
delay(wait_ms);
/* turn the LED off */
digitalWrite(LED_PIN, LOW);
wait_ms = random(10, 500);
delay(wait_ms);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment