Welcome to the Thornlea NoCO2 Project Site

Welcome to the official website for the Thornlea Secondary School, NoCO2 Launcher Project. For first time visitors, please start from the bottom of the blog and read your way up, doing so will allow you to read "up" to where we are today. There is also a convenient Archive of posts on the right sidebar under "Blog Archive". There are options to subscribe to the blog at the bottom of the page.

Enjoy,
-Calvin

Monday, April 29, 2013

I have a couple of pieces of preliminary WORKING code for the ARDUINO part of the design:
I'm using an Arduino Uno.


The First is the LED's timed out, there is no working Red in this, as it is just simple mock up with variable times.


void setup() {


// Pin 13 has an LED connected on most Arduino boards:
pinMode(1, OUTPUT); //Prestage Light(s)
pinMode(2, OUTPUT); //Stage Light(s)
pinMode(3, OUTPUT); //Yellow LED 1 (Top Amber)
pinMode(4, OUTPUT); //Yellow LED 2 (Middle Amber)
pinMode(5, OUTPUT); //Yellow LED 3 (Bottom Amber)
pinMode(6, OUTPUT); //Green LED (GO! Light)
pinMode(7, OUTPUT); //Red LED (Fault/ Falsestart Light)
pinMode(13, OUTPUT); //reset Light


 digitalWrite(1, HIGH); // 5 second Pre Stage
delay(5000);
digitalWrite(1, LOW); // PreStage LED turns off
delay(5);
digitalWrite(2, HIGH); // 3 second Stage LED
delay(3000);
digitalWrite(2, LOW); // Stage LED turns off
delay(5);
digitalWrite(3, HIGH); // Yellow led 1 on 0.5 second
delay(1000);
digitalWrite(3, LOW); // Yellow LED 1 turns off
delay(5);
digitalWrite(4, HIGH); // Yellow Led 2 on for 0.5 second
delay(1000);
digitalWrite(4, LOW); // LED turns 2 off
delay(5);
digitalWrite(5, HIGH); // Yellow Led 3 on for 0.5 second
delay(1000);
digitalWrite(5, LOW); // LED turns 3 off
delay(5);
digitalWrite(6, HIGH); // Green Led on for 15 seconds
delay(15000);
digitalWrite(6, LOW); // Green LED turns off for 5 minutes before sequence restart
delay(300);
}

void loop() {
 
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  }

NOTES:
The "delay" is the time in milliseconds that the light is active for. then the "digitalWrite (#, LOW)" turns off the LED (with the # being the Arduino pin that the LED (positive leg) is connected to).


------------------------------------------------------------------------------------------------------------

The next is the LED's with buttons which is the same code as above, however with two button 's connected to the 11 & 12 pins as prescribed in: http://arduino.cc/en/Tutorial/Button


//Set pin numbers
const int buttonPinL = 12;     // the number of the pushbutton pin for Track Right
const int buttonPinR = 11;     // the number of the pushbutton pin for Track Left

void setup() {

  {
    // Pin 13 has an LED connected on most Arduino boards:
    pinMode(1, OUTPUT); //Prestage Light(s)
    pinMode(2, OUTPUT); //Stage Light(s)
    pinMode(3, OUTPUT); //Yellow LED 1 (Top Amber)
    pinMode(4, OUTPUT); //Yellow LED 2 (Middle Amber)
    pinMode(5, OUTPUT); //Yellow LED 3 (Bottom Amber)
    pinMode(6, OUTPUT); //Green LED (GO! (L)ight)
    pinMode(8, OUTPUT); //Green LED R
    pinMode(7, OUTPUT); //Red LED Left Lane (Fault/ Falsestart Light)
    pinMode(10, OUTPUT); //Red LED Right Lane
    pinMode(13, OUTPUT); //reset light
    pinMode(buttonPinR, INPUT); //Right Track button input
    pinMode(buttonPinL, INPUT); //Left Track button input

    digitalWrite(1, HIGH); // 5 second Pre Stage
    delay(5000);
    digitalWrite(1, LOW); // PreStage LED turns off
    delay(5);
    digitalWrite(2, HIGH); // 3 second Stage LED
    delay(3000);
    digitalWrite(2, LOW); // Stage LED turns off
    delay(5);
    digitalWrite(3, HIGH); // Yellow led 1 on 0.5 second
    delay(1000);
    digitalWrite(3, LOW); // Yellow LED 1 turns off
    delay(5);
    digitalWrite(4, HIGH); // Yellow Led 2 on for 0.5 second
    delay(1000);
    digitalWrite(4, LOW); // LED turns 2 off
    delay(5);
    digitalWrite(5, HIGH); // Yellow Led 3 on for 0.5 second
    delay(1000);
    digitalWrite(5, LOW); // LED turns 3 off
    delay(5);
   
}
}

// variables will change:
int buttonStateR = 0;         // variable for reading the pushbutton status
int buttonStateL = 0;


void loop() {

  buttonStateR = digitalRead(buttonPinR);
  buttonStateL = digitalRead(buttonPinL);

  {
    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (buttonStateL == HIGH) {
      // turn LED on:  
      digitalWrite(7, HIGH);
    }
    else {
      // turn LED off:
      digitalWrite(7, LOW);
    }
    {
    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (buttonStateR == HIGH) {
      // turn LED on:  
      digitalWrite(10, HIGH);
    }
    else {
      // turn LED off:
      digitalWrite(10, LOW);
    }
  }
  {
    digitalWrite(6, HIGH) ; // Green Led on for 15 seconds
    digitalWrite(8, HIGH);
    digitalWrite(13, HIGH);
   }
 
  }


}

NOTES: the times for the tree have been changed, as well, now the buttons work, the next piece of code will move the buttons to the Analog Input's on the arduino board to save precious PWM pins. Keep in mind, Pin 1 can't be used, i've tried.


No comments:

Post a Comment