unused busin works ok

Dependencies:   C12832_lcd LM75B mbed

Committer:
avnisha
Date:
Tue Feb 18 12:45:39 2014 +0000
Revision:
0:70afbb61cc9a
ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
avnisha 0:70afbb61cc9a 1
avnisha 0:70afbb61cc9a 2 #include "mbed.h"
avnisha 0:70afbb61cc9a 3 #include "LM75B.h"
avnisha 0:70afbb61cc9a 4 #include "C12832_lcd.h"
avnisha 0:70afbb61cc9a 5
avnisha 0:70afbb61cc9a 6 #define T_START 1392096720 //RTC time = Mon, 10 Feb 2014 21:32:00 PDT
avnisha 0:70afbb61cc9a 7
avnisha 0:70afbb61cc9a 8 #define JOY_UP p16 // joystick related pins
avnisha 0:70afbb61cc9a 9 #define JOY_DOWN p13
avnisha 0:70afbb61cc9a 10 #define JOY_LEFT p12
avnisha 0:70afbb61cc9a 11 #define JOY_RIGHT p15
avnisha 0:70afbb61cc9a 12
avnisha 0:70afbb61cc9a 13 BusIn nibble(p12, p13, p14, p15);
avnisha 0:70afbb61cc9a 14
avnisha 0:70afbb61cc9a 15 void upDateLCD(C12832_LCD *lcd, float mycurrentTemp, time_t *mycurrentTime)
avnisha 0:70afbb61cc9a 16 {
avnisha 0:70afbb61cc9a 17 (*lcd).cls();
avnisha 0:70afbb61cc9a 18 (*lcd).locate(0,0);
avnisha 0:70afbb61cc9a 19 (*lcd).printf("Temp: %.2f\n", mycurrentTemp);
avnisha 0:70afbb61cc9a 20 //(*lcd).printf("Time: %s", ctime(mycurrentTime)); // don't use this one
avnisha 0:70afbb61cc9a 21 char buffer[20]; // strftime format begets .e.g. "May 19 03:10:50 PM"
avnisha 0:70afbb61cc9a 22 strftime(buffer, 20, "%b %d %I:%M:%S %p\n",localtime(mycurrentTime));//note pointer
avnisha 0:70afbb61cc9a 23 (*lcd).printf("%s", buffer);
avnisha 0:70afbb61cc9a 24 }
avnisha 0:70afbb61cc9a 25
avnisha 0:70afbb61cc9a 26 void upDateTerminal(Serial *pc, float mycurrentTemp, time_t *mycurrentTime, int myJoyVal)
avnisha 0:70afbb61cc9a 27 {
avnisha 0:70afbb61cc9a 28 (*pc).printf("myJoyVal = %d\n", myJoyVal);
avnisha 0:70afbb61cc9a 29 (*pc).printf("Current Temp: %.2f\n", mycurrentTemp);
avnisha 0:70afbb61cc9a 30 (*pc).printf("Time as seconds since January 1, 1970 = %d\n", *mycurrentTime);
avnisha 0:70afbb61cc9a 31 (*pc).printf("Time as a basic string = %s", ctime(mycurrentTime));//note pointer
avnisha 0:70afbb61cc9a 32 char buffer[20]; // strftime() format begets .e.g. "May 19 03:10:50 PM"
avnisha 0:70afbb61cc9a 33 strftime(buffer, 20, "%b %d %I:%M:%S %p\n", localtime(mycurrentTime));//note pointer
avnisha 0:70afbb61cc9a 34 (*pc).printf("Time as a custom formatted string = %s\n", buffer);
avnisha 0:70afbb61cc9a 35 }
avnisha 0:70afbb61cc9a 36
avnisha 0:70afbb61cc9a 37 void getMyTempnTime(LM75B *mytmpSns, float *mycurrentTemp, time_t *mycurrentTime)
avnisha 0:70afbb61cc9a 38 {
avnisha 0:70afbb61cc9a 39 *mycurrentTemp = (((*mytmpSns).read()*9/5)+32);
avnisha 0:70afbb61cc9a 40 *mycurrentTime = time(NULL);
avnisha 0:70afbb61cc9a 41 }
avnisha 0:70afbb61cc9a 42
avnisha 0:70afbb61cc9a 43
avnisha 0:70afbb61cc9a 44 void readJoyStick(BusIn *myJoyStick, int *myJoyVal)
avnisha 0:70afbb61cc9a 45 {
avnisha 0:70afbb61cc9a 46 int sampleJoyVal = *myJoyStick;
avnisha 0:70afbb61cc9a 47 wait(.04);
avnisha 0:70afbb61cc9a 48 if (sampleJoyVal != *myJoyStick) // if not stable, clear sample
avnisha 0:70afbb61cc9a 49 {
avnisha 0:70afbb61cc9a 50 *myJoyVal = 0;
avnisha 0:70afbb61cc9a 51 }
avnisha 0:70afbb61cc9a 52 else
avnisha 0:70afbb61cc9a 53 {
avnisha 0:70afbb61cc9a 54 switch (sampleJoyVal) //disallow "diagonal" combinations
avnisha 0:70afbb61cc9a 55 {
avnisha 0:70afbb61cc9a 56 case 0x1: // JOY_RIGHT
avnisha 0:70afbb61cc9a 57 case 0x2: // JOY_LEFT
avnisha 0:70afbb61cc9a 58 case 0x4: // JOY_DOWN
avnisha 0:70afbb61cc9a 59 case 0x8: // JOY_UP
avnisha 0:70afbb61cc9a 60 (*myJoyVal) = sampleJoyVal;
avnisha 0:70afbb61cc9a 61 break;
avnisha 0:70afbb61cc9a 62 default: (*myJoyVal) = 0; // JOY_IDLE
avnisha 0:70afbb61cc9a 63 break;
avnisha 0:70afbb61cc9a 64 }
avnisha 0:70afbb61cc9a 65 }
avnisha 0:70afbb61cc9a 66 }
avnisha 0:70afbb61cc9a 67
avnisha 0:70afbb61cc9a 68 /*******************************************************************
avnisha 0:70afbb61cc9a 69 * EXPERIMENT_F_CALL.CPP
avnisha 0:70afbb61cc9a 70 * Date: 2/17/2014 Author: George (Michael) Hey
avnisha 0:70afbb61cc9a 71 * MBED Program to read time and temperature periodically (~ every second)
avnisha 0:70afbb61cc9a 72 * and also to read the joystick, debounced.
avnisha 0:70afbb61cc9a 73 * Displays to the LCD screen temperature and time.
avnisha 0:70afbb61cc9a 74 * Displays to the PC terminal the joystick value, temperature and time.
avnisha 0:70afbb61cc9a 75 * Reference http://mbed.org/handbook/Time?action=view&revision=11592
avnisha 0:70afbb61cc9a 76 * http://mbed.org/users/petereiso/notebook/cc-time-functions/
avnisha 0:70afbb61cc9a 77 * This program puts all the peripherals inside main(), and passes
avnisha 0:70afbb61cc9a 78 * peripheral pointers to functions().
avnisha 0:70afbb61cc9a 79 *******************************************************************/
avnisha 0:70afbb61cc9a 80 int main()
avnisha 0:70afbb61cc9a 81 {
avnisha 0:70afbb61cc9a 82 C12832_LCD lcd;
avnisha 0:70afbb61cc9a 83 LM75B tmpSns(p28,p27);
avnisha 0:70afbb61cc9a 84 Serial pc(USBTX, USBRX); // tx, rx
avnisha 0:70afbb61cc9a 85 float currentTemp = 0;
avnisha 0:70afbb61cc9a 86 time_t currentTime = T_START; // see #define
avnisha 0:70afbb61cc9a 87 BusIn joyStick(JOY_UP,JOY_DOWN,JOY_LEFT,JOY_RIGHT);
avnisha 0:70afbb61cc9a 88 int joyVal = 28; // bogus value for debug
avnisha 0:70afbb61cc9a 89
avnisha 0:70afbb61cc9a 90 set_time(T_START); // RTC start time - see #define
avnisha 0:70afbb61cc9a 91 while (1) {
avnisha 0:70afbb61cc9a 92 time_t seconds = time(NULL);
avnisha 0:70afbb61cc9a 93 getMyTempnTime(&tmpSns, &currentTemp, &currentTime);
avnisha 0:70afbb61cc9a 94 readJoyStick(&joyStick, &joyVal);
avnisha 0:70afbb61cc9a 95 upDateLCD(&lcd, currentTemp, &currentTime);
avnisha 0:70afbb61cc9a 96 upDateTerminal(&pc, currentTemp, &currentTime, joyVal);
avnisha 0:70afbb61cc9a 97 wait(1.0);
avnisha 0:70afbb61cc9a 98 }
avnisha 0:70afbb61cc9a 99 return 0;
avnisha 0:70afbb61cc9a 100 }