Last active
August 29, 2015 14:11
-
-
Save extrasleepy/3cd2872c4359601850c8 to your computer and use it in GitHub Desktop.
Getting More Random
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
int randnumber; //long is another data type, holds a 32 bit numberfloa | |
void setup() { //set up outputs | |
pinMode(8, OUTPUT); | |
pinMode(9, OUTPUT); | |
pinMode(10, OUTPUT); | |
Serial.begin(9600); //set up serial communication | |
randomSeed(analogRead(0)); //this will make psudo random numbers seem more random | |
} | |
void loop() { | |
randnumber= random(9); //pick a random number between 0 and 8 | |
Serial.println(randnumber); //prints the random number to the serial window | |
if (randnumber==0){ //if conditional statement compares randnumber to 0. | |
digitalWrite(8, HIGH); | |
delay(200); | |
digitalWrite(8, LOW); | |
delay(200); | |
} //end of conditional statement | |
if (randnumber==1){ | |
digitalWrite(9, HIGH); | |
delay(200); | |
digitalWrite(9, LOW); | |
delay(200); | |
} | |
if (randnumber==2){ | |
digitalWrite(10, HIGH); | |
delay(200); | |
digitalWrite(10, LOW); | |
delay(200); | |
} | |
if (randnumber!=0 && randnumber!=1 && randnumber!=2){ //use "&&" to test multiple conditions, use != for NOT equal to | |
digitalWrite(8, HIGH); | |
digitalWrite(9, HIGH); | |
digitalWrite(10, HIGH); | |
delay(200); | |
digitalWrite(8, LOW); | |
digitalWrite(9, LOW); | |
digitalWrite(10, LOW); | |
delay(200); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment