Skip to content

Instantly share code, notes, and snippets.

@mjdargen
Created July 14, 2020 16:56
Show Gist options
  • Save mjdargen/bbcd7551f7c7f3fdf429430487e3b356 to your computer and use it in GitHub Desktop.
Save mjdargen/bbcd7551f7c7f3fdf429430487e3b356 to your computer and use it in GitHub Desktop.
/* Activity 01 - Random Blinky
Blinks LED chaotically based on a random number.
Uses onboard LED connected to pin 13.
*/
#define LED_PIN 13 // define LED pin
// put your setup code here, to run once:
void setup() {
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
// initialize digital pin 13 (LED) as an output
pinMode(LED_PIN, OUTPUT);
pinMode(2, OUTPUT);
}
// put your main code here, to run repeatedly:
void loop() {
// choose random number between 0 and 2, not including 2
int rand_num = random(0,2);
digitalWrite(LED_PIN, rand_num); // turn the LED on
digitalWrite(2, rand_num);
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment