Created
July 14, 2020 16:56
-
-
Save mjdargen/bbcd7551f7c7f3fdf429430487e3b356 to your computer and use it in GitHub Desktop.
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
/* 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