CaryCoders
/
demo_SX1276_standalone
standalone sx1276 demo program
Fork of SX1276_GPS by
main.cpp
- Committer:
- vtraveller
- Date:
- 2014-08-04
- Revision:
- 9:1501fb01ded6
- Parent:
- 7:d087e901b74b
- Child:
- 10:3fcab08717fc
File content as of revision 9:1501fb01ded6:
#include "mbed.h" #include "Adafruit_RGBLCDShield.h" //#include "MCP23017.h" Serial pc(SERIAL_TX, SERIAL_RX); MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40); Adafruit_RGBLCDShield lcd(mcp23017); enum EExtraChars { eUp = 0, eDown, eDegree }; void CreateChars() { uint8_t k_aUp[] = { 0x4,0xe,0x1f,0x15,0x4,0x4,0x4,0x4 }; uint8_t k_aDown[] = { 0x4,0x4,0x4,0x4,0x15,0x1f,0xe,0x4 }; uint8_t k_aDegree[] = { 0xc,0x12,0x12,0xc,0x0,0x0,0x0,0x0 }; lcd.createChar(eUp,k_aUp); lcd.createChar(eDown,k_aDown); lcd.createChar(eDegree,k_aDegree); } void Initialise() { lcd.begin(16,2); CreateChars(); lcd.setCursor(0,0); lcd._putc(eUp); lcd.setCursor(0,1); lcd._putc(eDown); } // Allows to set the backlight, if the LCD backpack is used void SetBacklight(unsigned char status) { pc.printf("Backlight: %i\r\n", status); mcp23017.digitalWrite(8, (~(status >> 2) & 0x1)); mcp23017.digitalWrite(7, (~(status >> 1) & 0x1)); mcp23017.digitalWrite(6, (~status & 0x1)); } uint8_t CheckKeys() { static uint8_t lastButtons = lcd.readButtons(); uint8_t buttons = lcd.readButtons(); if (buttons) { if (buttons != lastButtons) { lastButtons = buttons; } lcd.setCursor(2,1); if (buttons & BUTTON_UP) { pc.printf("UP "); lcd.printf("UP "); } if (buttons & BUTTON_DOWN) { pc.printf("DOWN "); lcd.printf("DOWN "); } if (buttons & BUTTON_LEFT) { pc.printf("LEFT "); lcd.printf("LEFT "); } if (buttons & BUTTON_RIGHT) { pc.printf("RIGHT "); lcd.printf("RIGHT "); } if (buttons & BUTTON_SELECT) { pc.printf("SELECT "); lcd.printf("SELECT "); } lcd.printf(" "); } return buttons; } void ShowTemp(int in_nTemp) { lcd.setCursor(2,0); lcd.printf("Room: %i%cC ",in_nTemp,eDegree); } void SetTime ( uint8_t in_nHour, uint8_t in_nMin, uint8_t in_nDay, uint8_t in_nMonth, uint16_t in_nYear ) { tm sCurrentTime = { 0 }; sCurrentTime.tm_year = in_nYear - 1900; sCurrentTime.tm_mon = in_nMonth - 1; sCurrentTime.tm_mday = in_nDay; sCurrentTime.tm_hour = in_nHour; sCurrentTime.tm_min = in_nMin; time_t nCurrentTime = mktime(&sCurrentTime); set_time(nCurrentTime); } void ShowTime() { lcd.setCursor(2,1); time_t rawtime = time(0); tm * timeinfo = localtime(&rawtime); lcd.printf ("%02i:%02i:%02i ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); } int main() { pc.printf("\r\nInitialise LCD\r\n"); Initialise(); SetTime(11,48,4,8,2014); int nTemp = 28; ShowTemp(nTemp); time_t nLast = 0; while (true) { if (time(0) - nLast > 3) { ShowTime(); } uint8_t nKeys = CheckKeys(); if (nKeys) { if (nKeys & BUTTON_UP) nTemp++; if (nKeys & BUTTON_DOWN) nTemp--; ShowTemp(nTemp); nLast = time(0); } wait(0.2); } }