acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

TalkingClock.ino (1713B)

      1 #include "Arduino.h"
      2 #include "Audio.h"
      3 #include "SD.h"
      4 #include "SPI.h"
      5 #include "FS.h"
      6 #include "Ticker.h"
      7 
      8 // Digital I/O used
      9 #define SD_CS          5
     10 #define SPI_MOSI      23
     11 #define SPI_MISO      19
     12 #define SPI_SCK       18
     13 #define I2S_DOUT      25
     14 #define I2S_BCLK      27
     15 #define I2S_LRC       26
     16 
     17 Audio audio;
     18 Ticker ticker;
     19 struct tm timeinfo;
     20 time_t now;
     21 
     22 uint8_t hour    = 6;
     23 uint8_t minute  = 59;
     24 uint8_t sec     = 45;
     25 
     26 bool f_time     = false;
     27 int8_t timefile = -1;
     28 char chbuf[100];
     29 
     30 void tckr1s(){
     31     sec++;
     32     if(sec > 59)   {sec = 0;     minute++;}
     33     if(minute > 59){minute = 0; hour++;}
     34     if(hour > 23)  {hour = 0;}
     35     if(minute == 59 && sec == 50) f_time = true;  // flag will be set 10s before full hour
     36     Serial.printf("%02d:%02d:%02d\n", hour, minute, sec);
     37 }
     38 
     39 void setup() {
     40     Serial.begin(115200);
     41     SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
     42     SD.begin(SD_CS);
     43     audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
     44     audio.setVolume(10); // 0...21
     45     ticker.attach(1, tckr1s);
     46 }
     47 
     48 void loop(){
     49     audio.loop();
     50     if(f_time == true){
     51         f_time = false;
     52         timefile = 3;
     53         uint8_t next_hour = hour + 1;
     54         if(next_hour == 25) next_hour = 1;
     55         sprintf(chbuf, "/voice_time/%03d.mp3", next_hour);
     56         audio.connecttoFS(SD, chbuf);
     57     }
     58 }
     59 
     60 void audio_eof_mp3(const char *info){  //end of file
     61     //Serial.printf("file :%s\n", info);
     62     if(timefile>0){
     63         if(timefile==1){audio.connecttoFS(SD, "/voice_time/080.mp3");     timefile--;}  // stroke
     64         if(timefile==2){audio.connecttoFS(SD, "/voice_time/200.mp3");     timefile--;}  // precisely
     65         if(timefile==3){audio.connecttoFS(SD, "/voice_time/O'clock.mp3"); timefile--;}
     66     }
     67 }
     68