Friday, September 13, 2019

Saul-Open Lab-35 min-Random blinking LED

Today,for open lab I finalized my code so that it generated a random number and started blinking an LED.I connected my Arduino to my breadboard and got an external LED on my breadboard to start randomly flashing.
  Listed below is my code,along with an image of my breadboard and Arduino;

      long randNumber;
const int arduinoBoardLED = 13;    // LED on pin 13
int myDelayTime = 0;  // Use to control the delay time used when calling delay() function


void setup() {
 
  Serial.begin(9600);
   pinMode(arduinoBoardLED, OUTPUT);

  // 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));
}

void loop() {
  // print a random number from 0 to 299
  randNumber = random(300);
  Serial.println(randNumber);

  // print a random number from 10 to 19
  randNumber = random(10, 20);
  Serial.println(randNumber);
 
 

  delay(500);

 digitalWrite(arduinoBoardLED, HIGH); //Set the LED pin to HIGH. This turns it On
  delay(myDelayTime);
  digitalWrite(arduinoBoardLED, LOW); //Set the LED pin to LOW. This turns it Off
  digitalWrite(arduinoBoardLED, HIGH); //Set the LED pin to HIGH. This turns it On
  digitalWrite(arduinoBoardLED, LOW); //Set the LED pin to LOW. This turns it Off
  delay(myDelayTime);
  Serial.print(".");   
  myDelayTime = myDelayTime + 20;
  if (myDelayTime > 300)
 
  // 
    {   
      myDelayTime = 10;   
      Serial.println("R");
    }
}




No comments:

Post a Comment