Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define clock_speed 16e6
- #define RED_PIN 8
- #define YELLOW_PIN 10
- #define GREEN_PIN 12
- //define the delays
- int red_on = 3000, red_yellow_on = 1000, green_on = 3000, green_blink = 5000, yellow_on = 1000;
- int delay_timer(int miliseconds){
- int count = 0;
- while(true){
- if(TCNT0 >= clock_speed) {
- TCNT0 = 0;
- count++;
- if(count == miliseconds) {
- count = 0;
- break;
- }
- }
- }
- return 0;
- }
- void setup() {
- // put your setup code here, to run once:
- // define the pins connected
- pinMode(RED_PIN, OUTPUT);
- pinMode(YELLOW_PIN, OUTPUT);
- pinMode(GREEN_PIN, OUTPUT);
- //set up timer
- TCCR0A = 0b00000000;
- TCCR0B = 0b00000101;
- TCNT0 = 0;
- }
- void loop() {
- // put your main code here, to run repeatedly:
- //to make red led on
- digitalWrite(RED_PIN, HIGH);
- delay_timer(red_on);
- //to make yellow led on
- digitalWrite(YELLOW_PIN, HIGH);
- delay_timer(red_yellow_on);
- //turning off red pin and yellow pin
- digitalWrite(RED_PIN, LOW);
- digitalWrite(YELLOW_PIN, LOW);
- //turning green on
- digitalWrite(GREEN_PIN, HIGH);
- delay_timer(green_on);
- //turning green off
- digitalWrite(GREEN_PIN, LOW);
- //for truning green on and off for three times
- for(int i = 0; i < 3; i++) {
- delay_timer(green_blink);
- digitalWrite(GREEN_PIN, HIGH);
- delay_timer(green_blink);
- digitalWrite(GREEN_PIN, LOW);
- }
- //for turning on yellow
- digitalWrite(YELLOW_PIN, HIGH);
- delay_timer(yellow_on);
- digitalWrite(YELLOW_PIN, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement