The first week of the Physical Computing Workshop. First up, blinking an Led. Then making two different led’s blink.

   

 Flashing 8 led’s, one after the other.

Flashing 8 led’s, forward then back!

 

Code:

/*
Jonathan MunroWk1 – Task 3 – Flashing 8Leds, one after the other for one second each and wait another
second before flashing the next.
*/void setup() {
// initialize the ouput pins

pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);

}

void loop() {
digitalWrite(12, HIGH);   // Turn Led 12 on
delay(1000);              // wait for a second
digitalWrite(12, LOW);    // set the LED 12 off
delay(1000);              // wait for a second
digitalWrite(11, HIGH);   // set the LED 11 on
delay(1000);              // wait for a second
digitalWrite(11, LOW);    // set the LED 11 off
delay(1000);
digitalWrite(10, HIGH);   // Turn Led 10 on
delay(1000);              // wait for a second
digitalWrite(10, LOW);    // set the LED 10 off
delay(1000);              // wait for a second
digitalWrite(9, HIGH);   // set the LED 9 on
delay(1000);              // wait for a second
digitalWrite(9, LOW);    // set the LED 9 off
delay(1000);
digitalWrite(8, HIGH);   // Turn Led 8 on
delay(1000);              // wait for a second
digitalWrite(8, LOW);    // set the LED 8 off
delay(1000);              // wait for a second
digitalWrite(7, HIGH);   // set the LED 7 on
delay(1000);              // wait for a second
digitalWrite(7, LOW);    // set the LED 7 off
delay(1000);
digitalWrite(6, HIGH);   // set the LED 6 on
delay(1000);              // wait for a second
digitalWrite(6, LOW);    // set the LED 6 off
delay(1000);
digitalWrite(5, HIGH);   // set the LED 5 on
delay(1000);              // wait for a second
digitalWrite(5, LOW);    // set the LED 5 off
delay(1000);
}

 

 

//Jonathan Munro
// Wk1 – Task 3c//Turn on the lights in a random pattern, the code works, but with interesting results. Some of the Leds are left on, whist //others come on as well, I wasn’t expecting this, although it does make perfect sense.//LED Pin Variables, Using an array, The range will be from 0-7 rather than 1-8
int ledPins[] = {12,11,10,9,8,7,6,5};

void setup()
{

for(int i = 0; i < 8; i++){      // a Loop which will repete 8 Times
pinMode(ledPins[random(i)],OUTPUT); // This sends each led to the output, using the random
}

}

void loop()  // Repeat the code
{
oneAfterAnotherLoop();   //This will execute the code below, which is sending the led’s loop through the sequence of lights

}

void oneAfterAnotherLoop(){
int delayTime = 50; //the off state of the last led, in this case 1/20 second
//make smaller for quicker switching and larger for slower

//Turn Each LED on one after another
for(int i = 0; i <= 7; i++){
digitalWrite(ledPins[random(i)], HIGH);  //Turns on LED’s in the array randomly
delay(delayTime);
}

//Turn Each LED off one after another
for(int i = 7; i >= 0; i–){  //This is the reverse of the counting up, but this time it counts down

digitalWrite(ledPins[random(i)], LOW);  //Turns off LED’s in the array randomly
delay(delayTime);
}

}

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>