pong game added to the main sketch

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor

Fork of MainSketch by IoT Ox

Committer:
Owenmatthewmcgowan
Date:
Wed May 24 16:15:04 2017 +0000
Revision:
13:50289d0ac834
Parent:
11:1da15361a35b
Added Settings page

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mlin 11:1da15361a35b 1 #include "Rtc_Ds1307.h"
mlin 9:eee503060d69 2 Rtc_Ds1307 rtc(I2C_SDA, I2C_SCL);
mlin 9:eee503060d69 3 Rtc_Ds1307::Time_rtc tm_c = {};
mlin 9:eee503060d69 4 Rtc_Ds1307::Time_rtc tm_a = {};
mlin 9:eee503060d69 5 char buffer[128];
mlin 9:eee503060d69 6 int readptr = 0;
mlin 9:eee503060d69 7
mlin 9:eee503060d69 8
mlin 11:1da15361a35b 9 void read_time()
mlin 11:1da15361a35b 10 {
mlin 11:1da15361a35b 11 // perform read
mlin 9:eee503060d69 12 pc.printf("Performing read operation\n\r");
mlin 9:eee503060d69 13 int n = 0;
mlin 9:eee503060d69 14 do {
mlin 9:eee503060d69 15 n++;
mlin 9:eee503060d69 16 } while(!rtc.getTime(tm_c));
mlin 11:1da15361a35b 17 pc.printf("The current time is : %02d:%02d:%02d\n\r", tm_c.hour, tm_c.min, tm_c.sec);
mlin 11:1da15361a35b 18 pc.printf("The current date is : %s, %02d/%02d/%04d\n\r", rtc.weekdayToString(tm_c.wday), tm_c.mon, tm_c.date, tm_c.year);
mlin 11:1da15361a35b 19 pc.printf("Tried to read %d times\n\r",n);
mlin 9:eee503060d69 20 }
mlin 9:eee503060d69 21
mlin 11:1da15361a35b 22 void write()
mlin 11:1da15361a35b 23 {
mlin 9:eee503060d69 24 // perform write
mlin 9:eee503060d69 25 pc.printf("Enter the date (date 0..31)");
mlin 9:eee503060d69 26 pc.scanf("%d", &tm_c.date);
mlin 9:eee503060d69 27 pc.printf("Enter the date (month 1..12)");
mlin 9:eee503060d69 28 pc.scanf("%d", &tm_c.mon);
mlin 9:eee503060d69 29 pc.printf("Enter the date (year)");
mlin 9:eee503060d69 30 pc.scanf("%d", &tm_c.year);
mlin 9:eee503060d69 31 pc.printf("Enter the time (hours 0..23)");
mlin 9:eee503060d69 32 pc.scanf("%d", &tm_c.hour);
mlin 9:eee503060d69 33 pc.printf("Enter the time (minutes 0..59)");
mlin 9:eee503060d69 34 pc.scanf("%d", &tm_c.min);
mlin 9:eee503060d69 35 pc.printf("Enter the time (seconds 0..59)");
mlin 9:eee503060d69 36 pc.scanf("%d", &tm_c.sec);
mlin 9:eee503060d69 37 pc.printf("Performing write operation\n\r");
mlin 11:1da15361a35b 38
mlin 11:1da15361a35b 39 while(pc.readable())
mlin 11:1da15361a35b 40
mlin 9:eee503060d69 41 pc.getc();
mlin 9:eee503060d69 42 int n = 0;
mlin 11:1da15361a35b 43 while (!rtc.setTime(tm_c, true, false)) { //set the Time in RTC Param : ( Time container, Start Clock, Twelve Hour Clock)
mlin 11:1da15361a35b 44 n++;
mlin 9:eee503060d69 45 }
mlin 11:1da15361a35b 46 pc.printf("Tried to write %d times\n\r",n);
mlin 9:eee503060d69 47 }
mlin 9:eee503060d69 48
mlin 9:eee503060d69 49 //other RTC functions:
mlin 9:eee503060d69 50 //rtc.startClock();
mlin 9:eee503060d69 51 //rtc.stopClock();
mlin 9:eee503060d69 52 //square wave
mlin 9:eee503060d69 53 // int rs;
mlin 9:eee503060d69 54 // pc.printf("Please specify the frequency : [0 = 1Hz, 1 = 4.096kHz, 2 = 8.192kHz, 3 = 32.768kHz] ");
mlin 9:eee503060d69 55 // scanf("%d", &rs);
mlin 9:eee503060d69 56 // pc.printf("Enabling the output with %d option\n", rs);
mlin 9:eee503060d69 57 // rtc.setSquareWaveOutput(true, (Rtc_Ds1307::SqwRateSelect_t)rs);
mlin 9:eee503060d69 58
mlin 9:eee503060d69 59
mlin 9:eee503060d69 60 //square wave off
mlin 9:eee503060d69 61 //rtc.setSquareWaveOutput(false, Rtc_Ds1307::RS1Hz);