Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Created: Fri Dec 2 16
- * Processor: ATmega328P
- * Compiler: Arduino AVR
- */
- #define DEBUG // Definizione che permette il debug
- // Se commentato, nessun debug
- #include <TimerOne.h> // usato per le temporizzazioni
- #define INBTN 2 // segnale di ingresso
- #define TMPRESS 10 // piedino del suono
- #define TIMEOUT 7200000UL // fine tempo contatore
- #define NUMCOLS 4 // numero di colonne
- #define NUMROWS 5 // numero di righe
- #define MAX_LEDS NUMCOLS * NUMROWS // numero di led
- #define BLINKTIME 10
- uint8_t data[NUMCOLS];
- uint8_t led_count = 0;
- uint8_t ticks = 0;
- uint32_t period = 0; // periodo da contare per 2 ore
- uint8_t led_blink = 1;
- bool push_btn;
- void countdown () {
- period = millis();
- #ifdef DEBUG
- Serial.println("Inizio il conteggio");
- #endif
- while (period < (millis()-TIMEOUT)) {};
- clrmem();
- led_count = 0;
- }
- void refresh() {
- if (ticks < NUMCOLS-1) ticks++;
- else ticks = 0;
- PORTC = 0;
- PORTB = data[ticks];
- bitWrite(PORTC, ticks, 1);
- delay(23);
- }
- void clrmem() {
- for (uint8_t x=0; x < NUMCOLS; x++) data[x] = 0;
- }
- void btn_press() {
- uint8_t col;
- if (pulseIn(INBTN,LOW) > TMPRESS && (led_blink == 1)) {
- #ifdef DEBUG
- Serial.print("led_count = ");
- Serial.println(led_count, DEC);
- #endif
- push_btn = 1;
- }
- if (push_btn) {
- if (led_blink < 5) {
- led_blink++;
- col = led_count / NUMROWS;
- bitWrite(data[col], led_count % NUMROWS, led_blink % 2);
- delay(BLINKTIME);
- }
- else {
- led_count++;
- led_blink = 1;
- push_btn = 0;
- }
- }
- }
- void setup(){
- #ifdef DEBUG
- Serial.begin(57600);
- #endif
- for (uint8_t x=8; x < 23; x++) {
- pinMode(x, OUTPUT);
- }
- clrmem();
- pinMode(INBTN, INPUT_PULLUP);
- #ifdef DEBUG
- Serial.println(F("Monitor pronto"));
- #endif
- Timer1.initialize(9761); // set a timer of length 5 milliseconds
- Timer1.attachInterrupt(refresh); // attach the service routine here
- }
- void loop() {
- btn_press();
- if (led_count >= MAX_LEDS) countdown();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement