Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ShiftLCD.h>
- #include <Wire.h>
- #include <PCF8583.h>
- ShiftLCD lcd(2, 4, 3);
- #define LCD_BL_PIN 0x04
- #define LCD_LED_PIN 0x08
- int correct_address = 0;
- PCF8583 p (0xA0);
- char serIn[6] = "0";
- char mailCounter[5] = "0";
- int hourSet;
- int minSet;
- int u;
- unsigned long currtime;
- int startuptune[] = {
- 262, 196, 262, 196};
- int mailtune[] = {
- 196, 196, 262};
- byte custchar[8][8] = {
- {
- B11111,
- B11111,
- B11111,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000
- }
- , {
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B11111,
- B11111,
- B11111
- }
- , {
- B11111,
- B11111,
- B11111,
- B00000,
- B00000,
- B11111,
- B11111,
- B11111
- }
- , {
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00110,
- B00110,
- B00110
- }
- , {
- B00000,
- B00000,
- B00000,
- B01110,
- B01110,
- B01110,
- B00000,
- B00000
- }
- , {
- B11111,
- B11111,
- B11011,
- B11011,
- B11111,
- B11111,
- B00000,
- B00000
- }
- , {
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000
- }
- , {
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111
- }
- };
- byte bignums[12][2][3] = {
- {
- {
- 7, 0, 7 }
- ,
- {
- 7, 1, 7 }
- }
- ,{
- {
- 0, 7, 6 }
- ,
- {
- 1, 7, 1 }
- }
- ,{
- {
- 0, 0, 7 }
- ,
- {
- 7, 2, 2 }
- }
- ,{
- {
- 0, 2, 7 }
- ,
- {
- 1, 1, 7 }
- }
- ,{
- {
- 7, 1, 7 }
- ,
- {
- 6, 6, 7 }
- }
- ,{
- {
- 7, 2, 2 }
- ,
- {
- 1, 1, 7 }
- }
- ,{
- {
- 7, 2, 2 }
- ,
- {
- 7, 1, 7 }
- }
- ,{
- {
- 0, 0, 7 }
- ,
- {
- 6, 7, 6 }
- }
- ,{
- {
- 7, 2, 7 }
- ,
- {
- 7, 1, 7 }
- }
- ,{
- {
- 7, 2, 7 }
- ,
- {
- 6, 6, 7 }
- }
- ,{
- {
- 7, 0, 0 }
- ,
- {
- 7, 1, 1 }
- }
- ,{
- {
- 6, 6, 6 }
- ,
- {
- 6, 6, 6 }
- }
- };
- void loadchars() {
- lcd.command(64);
- for (int i = 0; i < 8; i++)
- lcd.createChar(i, custchar[i]);
- lcd.home();
- }
- void printbigchar(byte digit, byte col, byte row, byte symbol = 0) {
- if (digit > 11) return;
- for (int i = 0; i < 2; i++) {
- lcd.setCursor(col*4, row + i);
- for (int j = 0; j < 3; j++) {
- lcd.write(bignums[digit][i][j]);
- }
- }
- if (symbol == 0) {
- lcd.setCursor(col*4 + 3, row);
- lcd.write(6);
- lcd.setCursor(col*4 + 3, row + 1);
- lcd.write(6);
- }
- else if (symbol == 1) {
- lcd.setCursor(col*4 + 3, row);
- lcd.write(6);
- lcd.setCursor(col*4 + 3, row + 1);
- lcd.write(3);
- }
- else if (symbol == 2) {
- lcd.setCursor(col*4 + 3, row);
- lcd.write(4);
- lcd.setCursor(col*4 + 3, row + 1);
- lcd.write(4);
- }
- lcd.setCursor(col*4 + 4, row);
- }
- void bigprint(float number, int col)
- {
- printbigchar(number / 10,col,0);
- printbigchar(int(number)%10,col+1,0,1);
- printbigchar(int(number*10)%10,col+2,0);
- }
- void bigclock(int time, int col, char mails[5])
- {
- p.get_time();
- printbigchar(p.hour/10,col,0);
- if(p.second%2==0) printbigchar(p.hour%10,col+1,0,2);
- else printbigchar(p.hour%10,col+1,0);
- printbigchar(p.minute/10,col+2,0);
- printbigchar(p.minute%10,col+3,0);
- /*printbigchar(11,col+4,0);*/
- lcd.setCursor(16,0);
- if (mails[0]=='0' && mails[1]==0) lcd.print("No");
- else lcd.print(mails);
- lcd.setCursor(16,1);
- if (mails[0]=='0' && mails[1]==0) {
- lcd.print("Mail");
- digitalWrite(10, LOW);
- }
- else lcd.print("Msgs");
- }
- void serial()
- {
- // ***goSerial comms***
- if(Serial.available()) {
- u=0;
- serIn[0]=0;
- while (Serial.available()>0){
- serIn[u++] = Serial.read(); //read Serial
- }
- serIn[u]=0;
- // 0 => reset mail counter
- if (serIn[0]=='0') {
- mailCounter[0]='0';
- mailCounter[1]=0;
- }
- // T => set time
- if (serIn[0]=='T') {
- p.hour=(serIn[1]-48)*10+(serIn[2]-48);
- p.minute=(serIn[3]-48)*10+(serIn[4]-48);
- p.second=0;
- p.set_time();
- for(int i=0;i<20;i++){
- lcd.scrollDisplayRight();
- delay(20);
- }
- lcd.clear();
- lcd.setCursor(1,0);
- lcd.print("Time has been set!");
- lcd.setCursor(7,1);
- if(!(p.hour/10)) lcd.print("0");
- lcd.print(p.hour); lcd.print(":");
- if(!(p.minute/10)) lcd.print("0");
- lcd.print(p.minute);
- for(int i=0;i<20;i++){
- lcd.scrollDisplayLeft();
- delay(20);
- }
- delay(5000);
- for(int i=0;i<20;i++){
- lcd.scrollDisplayRight();
- delay(20);
- }
- lcd.clear();
- for(int i=0;i<20;i++){
- lcd.scrollDisplayLeft();
- }
- serIn[0]='0';
- }
- // M => set mail counter
- if (serIn[0]=='M') {
- for (u=1;serIn[u]!=0;u++) {
- mailCounter[u-1]=serIn[u];
- }
- mailCounter[u+1]=0;
- }
- // play the tune
- if (mailCounter[0]!='0') {
- for (int note=0; note<3; ++note) {
- tone(10,mailtune[note],75);
- delay(100);
- noTone(10);
- digitalWrite(10, HIGH);
- }
- }
- }
- // ***End serial comms***
- }
- void setup()
- {
- Serial.begin(9600);
- lcd.begin(20, 2);
- loadchars();
- for (int note=0; note<4; ++note) {
- tone(10,startuptune[note],75);
- delay(100);
- noTone(10);
- }
- }
- double temp(int pin)
- {
- double Temp;
- Temp = log(((10240000/analogRead(pin)) - 10000));
- Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
- Temp = Temp - 273.15;
- return Temp;
- }
- void bigtemp()
- {
- bigprint(temp(0),0);
- lcd.setCursor(14,0);
- lcd.write(5);
- printbigchar(10,4,0);
- }
- void loop()
- {
- for(int i=0;i<40;i++){
- bigtemp();
- delay(100);
- serial();
- }
- for(int i=0;i<20;i++){
- lcd.scrollDisplayRight();
- delay(50);
- }
- printbigchar(11,4,0);
- bigclock(0,0,mailCounter);
- for(int i=0;i<20;i++){
- lcd.scrollDisplayRight();
- delay(50);
- }
- for(int i=0;i<40;i++){
- bigclock(0,0,mailCounter);
- delay(100);
- serial();
- }
- for(int i=0;i<20;i++){
- lcd.scrollDisplayRight();
- delay(50);
- }
- printbigchar(11,3,0);
- bigtemp();
- for(int i=0;i<20;i++){
- lcd.scrollDisplayRight();
- delay(50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement