added example for controlling a traffic light

This commit is contained in:
Sven Vogel 2023-10-27 17:59:15 +02:00
parent 3a8fa2a56e
commit f9ed357485
3 changed files with 51 additions and 2 deletions

View File

@ -4,11 +4,13 @@ extern void loop();
//#include "blink/blink.h" //#include "blink/blink.h"
//#include "button_poll/button.h" //#include "button_poll/button.h"
#include "button_interupt/button.h" //#include "button_interupt/button.h"
#include "trafficlight/trafficlight.h"
//#define BLINK //#define BLINK
//#define BUTTON_POLL //#define BUTTON_POLL
#define BUTTON_INTERRUPT //#define BUTTON_INTERRUPT
#define TRAFFIC_LIGHT
int main() { int main() {
init(); init();

View File

@ -0,0 +1,34 @@
//
// Created by servostar on 27.10.23.
//
#include "trafficlight.h"
#ifdef TRAFFIC_LIGHT
void init() {
// set Port B bit 0,1,2 to output mode
DDRB = 0b00000111;
// set port B bit 2 (red) to one
PORTB = 0b00000100;
}
void loop() {
_delay_ms(200);
// set red orange
PORTB ^= 0b00000010;
_delay_ms(200);
// set green
PORTB ^= 0b00000111;
_delay_ms(500);
// set orange
PORTB ^= 0b00000011;
_delay_ms(500);
// set to red
PORTB ^= 0b00000110;
}
#endif

View File

@ -0,0 +1,13 @@
//
// Created by servostar on 27.10.23.
//
#ifndef ARDUINO_TRAFFICLIGHT_H
#define ARDUINO_TRAFFICLIGHT_H
#include "prelude.h"
void init();
void loop();
#endif //ARDUINO_TRAFFICLIGHT_H