Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <DFPlayer_Mini_Mp3.h>
- #include <Wire.h>
- #include "SoftwareSerial.h"
- #include "RTClib.h"
- # define Start_Byte 0x7E
- # define Version_Byte 0xFF
- # define Command_Length 0x06
- # define End_Byte 0xEF
- # define Acknowledge 0x00
- # define ACTIVATED LOW
- SoftwareSerial serial(9, 8); // Tx = Pin 9
- SoftwareSerial mySerial(10, 11);
- RTC_DS3231 rtc;
- char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- boolean isPlaying = false;
- int button1Pin = 7;
- int button1State = 0;
- int sensorValue;
- void setup () {
- pinMode(13, OUTPUT);
- pinMode(button1Pin, INPUT);
- Serial.begin(9600) ;
- mySerial.begin (9600);
- serial.begin(9600);
- delay(1);
- Serial.flush();
- serial.flush();
- delay(1000);
- isPlaying = false;
- mp3_set_serial (mySerial);
- mp3_set_volume (30);
- timeeSetup();
- }//end of setup
- void loop () {
- char serialData[30];
- int lf = 10;
- unsigned char read1, read2, read3;
- int temp_int;
- char temp_string[40];
- button1State = digitalRead(button1Pin);
- if (serial.available() >= 15) {
- temp_int = serial.readBytesUntil(lf, serialData, 15);
- read1 = ((serialData[1] - '0') * 100) + ((serialData[2] - '0') * 10) + (serialData[3] - '0');
- read2 = ((serialData[6] - '0') * 100) + ((serialData[7] - '0') * 10) + (serialData[8] - '0');
- read3 = ((serialData[11] - '0') * 100) + ((serialData[12] - '0') * 10) + (serialData[13] - '0');
- Serial.print("SYS: ");
- Serial.print(read1);
- Serial.print(" DIY: ");
- Serial.println(read2);
- Serial.print("Pulse/Min: ");
- Serial.println(read3);
- timee();
- if (read3 > 10) {
- mp3_play (1);
- delay (13000);
- mp3_stop ();
- for (int i = 0; i < 30; i++) {
- serialData[i] = 0;
- }
- read1 = 0;
- read2 = 0;
- read3 = 0;
- Serial.flush();
- serial.flush();
- }
- }
- else if (button1State == LOW) {
- mp3_play (1);
- delay (13000);
- mp3_stop ();
- }
- }//end of loop
- void timeeSetup() {
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- while (1);
- }
- if (rtc.lostPower()) {
- Serial.println("RTC lost power, lets set the time!");
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- }
- }
- void timee() {
- DateTime now = rtc.now();
- Serial.print(now.year(), DEC);
- Serial.print('/');
- Serial.print(now.month(), DEC);
- Serial.print('/');
- Serial.println(now.day(), DEC);
- Serial.print(" (");
- Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
- Serial.println(") ");
- Serial.print(now.hour(), DEC);
- Serial.print(':');
- Serial.print(now.minute(), DEC);
- Serial.print(':');
- Serial.print(now.second(), DEC);
- Serial.println();
- }
- // name audio files to play [ mp3_play (3); ] == [ ./mp3/0003.mp3 ]
Add Comment
Please, Sign In to add comment