Commit 4ebca48a6d1007a2fae720318cee01e03a36f076

Authored by Enrique Díaz Roque
1 parent a25803e1
Exists in master and in 1 other branch dev

Updated ino

Showing 1 changed file with 33 additions and 9 deletions   Show diff stats
ino/src/sketch.ino
... ... @@ -2,11 +2,28 @@
2 2 #include <LCD.h>
3 3 #include <Time.h>
4 4  
  5 +#define SIZE 256
  6 +
  7 +// LCD stuff
  8 +
5 9 char ino_alias[16];
6 10 uint8_t last_second = 0;
7 11 uint8_t lcd_swap = 0;
8 12 LCD lcd;
9 13  
  14 +// ADC stuff
  15 +
  16 +volatile uint8_t buffer[SIZE];
  17 +volatile uint8_t index = 0;
  18 +
  19 +// ISR routines
  20 +
  21 +ISR(ADC_vect) {
  22 + buffer[index++] = ADCH;
  23 +}
  24 +
  25 +// Procedures && functions
  26 +
10 27 void print_time_lcd() {
11 28 bool alias_turn;
12 29 char buffer[4];
... ... @@ -41,7 +58,18 @@ void print_time_lcd() {
41 58 lcd.print(buffer);
42 59 }
43 60  
  61 +void hardware_setup() {
  62 + ADCSRA |= (0<<ADPS2) | (0<<ADPS1) | (1<<ADPS0) | (1<<ADATE) | (1<<ADEN) | (1<<ADIE);
  63 + ADMUX |= (1<<REFS0) | (1<<ADLAR);
  64 + ADMUX &= ~(1<<REFS1);
  65 + ADCSRB &= ~((1<<ADTS2) | (1<<ADTS1) | (1<<ADTS0));
  66 + ADCSRA |= (1<<ADSC);
  67 +}
  68 +
  69 +// Main
  70 +
44 71 void setup() {
  72 + hardware_setup();
45 73 Serial.begin(115200);
46 74  
47 75 lcd.clear_screen();
... ... @@ -66,17 +94,13 @@ void setup() {
66 94 lcd.clear_screen();
67 95 lcd.print("Byte malo :'(");
68 96 }
69   -
70   - lcd.clear_screen();
71   - lcd.print("APP says I'm:");
72   - lcd.set_cursor(1, 2);
73   - lcd.print(ino_alias);
74 97 }
75 98  
76 99 void loop() {
77   - if (last_second != second()) {
  100 + uint8_t current;
  101 + if (current = second(), last_second != current) {
78 102 print_time_lcd();
79   - last_second = second();
  103 + last_second = current;
80 104 }
81 105  
82 106 if (Serial.available() < 1) {
... ... @@ -101,7 +125,7 @@ void loop() {
101 125 while (Serial.available() < HW_DATE_SIZE);
102 126  
103 127 uint32_t unix_time = 0;
104   - for (uint8_t i = HW_DATE_SIZE-1; i >= 0; i++) {
  128 + for (uint8_t i = HW_DATE_SIZE-1; i >= 0; i--) {
105 129 unix_time += Serial.read() << (8*i);
106 130 }
107 131 setTime(unix_time);
... ... @@ -121,7 +145,7 @@ void loop() {
121 145 break;
122 146 }
123 147 default:
124   - // Command ignored
  148 + // This should never happen, command ignored
125 149 break;
126 150 }
127 151 }
... ...