standalone sx1276 demo program

Dependencies:   SX1276Lib mbed

Fork of SX1276_GPS by CaryCoders

Committer:
vtraveller
Date:
Sat Aug 02 16:05:40 2014 +0000
Revision:
6:a6be2aede8f2
Parent:
5:6c9ee7e3a20c
Child:
7:d087e901b74b
Updated with some clean ups

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:88d87b1c1f8b 1 #include "mbed.h"
vtraveller 4:d70e37f6c6bd 2
vtraveller 4:d70e37f6c6bd 3 #include "Adafruit_RGBLCDShield.h"
vtraveller 4:d70e37f6c6bd 4 //#include "MCP23017.h"
wim 0:88d87b1c1f8b 5
vtraveller 3:ed09f95739df 6 Serial pc(SERIAL_TX, SERIAL_RX);
wim 0:88d87b1c1f8b 7
vtraveller 3:ed09f95739df 8 MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40);
vtraveller 6:a6be2aede8f2 9 Adafruit_RGBLCDShield lcd(mcp23017,pc);
vtraveller 3:ed09f95739df 10
vtraveller 3:ed09f95739df 11 // Allows to set the backlight, if the LCD backpack is used
vtraveller 3:ed09f95739df 12 void SetBacklight(unsigned char status)
vtraveller 3:ed09f95739df 13 {
vtraveller 3:ed09f95739df 14 pc.printf("Backlight: %i\n\r", status);
vtraveller 3:ed09f95739df 15
vtraveller 3:ed09f95739df 16 mcp23017.digitalWrite(8, (~(status >> 2) & 0x1));
vtraveller 3:ed09f95739df 17 mcp23017.digitalWrite(7, (~(status >> 1) & 0x1));
vtraveller 3:ed09f95739df 18 mcp23017.digitalWrite(6, (~status & 0x1));
vtraveller 3:ed09f95739df 19 }
wim 0:88d87b1c1f8b 20
vtraveller 4:d70e37f6c6bd 21 void loop()
vtraveller 3:ed09f95739df 22 {
vtraveller 4:d70e37f6c6bd 23 // set the cursor to column 0, line 1
vtraveller 4:d70e37f6c6bd 24 // (note: line 1 is the second row, since counting begins with 0):
vtraveller 6:a6be2aede8f2 25 lcd.setCursor(10, 1);
vtraveller 6:a6be2aede8f2 26
vtraveller 6:a6be2aede8f2 27 //lcd.cursor();
vtraveller 6:a6be2aede8f2 28 //lcd.blink();
vtraveller 4:d70e37f6c6bd 29
vtraveller 4:d70e37f6c6bd 30 uint8_t buttons = lcd.readButtons();
vtraveller 4:d70e37f6c6bd 31
vtraveller 6:a6be2aede8f2 32 lcd.setBacklight(buttons ? 1 : 0);
vtraveller 6:a6be2aede8f2 33
vtraveller 4:d70e37f6c6bd 34 if (buttons)
vtraveller 4:d70e37f6c6bd 35 {
vtraveller 4:d70e37f6c6bd 36 lcd.clear();
vtraveller 4:d70e37f6c6bd 37 lcd.setCursor(0,0);
vtraveller 4:d70e37f6c6bd 38
vtraveller 4:d70e37f6c6bd 39 if (buttons & BUTTON_UP)
vtraveller 4:d70e37f6c6bd 40 {
vtraveller 4:d70e37f6c6bd 41 pc.printf("UP ");
vtraveller 4:d70e37f6c6bd 42
vtraveller 4:d70e37f6c6bd 43 lcd.printf("UP ");
vtraveller 4:d70e37f6c6bd 44 }
vtraveller 4:d70e37f6c6bd 45
vtraveller 4:d70e37f6c6bd 46 if (buttons & BUTTON_DOWN)
vtraveller 4:d70e37f6c6bd 47 {
vtraveller 4:d70e37f6c6bd 48 pc.printf("DOWN ");
vtraveller 4:d70e37f6c6bd 49
vtraveller 4:d70e37f6c6bd 50 lcd.printf("DOWN ");
vtraveller 4:d70e37f6c6bd 51 }
vtraveller 4:d70e37f6c6bd 52
vtraveller 4:d70e37f6c6bd 53 if (buttons & BUTTON_LEFT)
vtraveller 4:d70e37f6c6bd 54 {
vtraveller 4:d70e37f6c6bd 55 pc.printf("LEFT ");
vtraveller 4:d70e37f6c6bd 56
vtraveller 4:d70e37f6c6bd 57 lcd.printf("LEFT ");
vtraveller 4:d70e37f6c6bd 58 }
vtraveller 4:d70e37f6c6bd 59
vtraveller 4:d70e37f6c6bd 60 if (buttons & BUTTON_RIGHT)
vtraveller 4:d70e37f6c6bd 61 {
vtraveller 4:d70e37f6c6bd 62 pc.printf("RIGHT ");
vtraveller 4:d70e37f6c6bd 63
vtraveller 4:d70e37f6c6bd 64 lcd.printf("RIGHT ");
vtraveller 4:d70e37f6c6bd 65 }
vtraveller 4:d70e37f6c6bd 66
vtraveller 4:d70e37f6c6bd 67 if (buttons & BUTTON_SELECT)
vtraveller 4:d70e37f6c6bd 68 {
vtraveller 4:d70e37f6c6bd 69 pc.printf("SELECT ");
vtraveller 4:d70e37f6c6bd 70
vtraveller 4:d70e37f6c6bd 71 lcd.printf("SELECT ");
vtraveller 4:d70e37f6c6bd 72 }
vtraveller 4:d70e37f6c6bd 73 }
vtraveller 6:a6be2aede8f2 74
vtraveller 6:a6be2aede8f2 75 lcd.setCursor(0,0);
vtraveller 6:a6be2aede8f2 76 lcd._putc('A');
vtraveller 6:a6be2aede8f2 77
vtraveller 6:a6be2aede8f2 78 lcd.display();
vtraveller 3:ed09f95739df 79 }
vtraveller 3:ed09f95739df 80
vtraveller 3:ed09f95739df 81 int main()
vtraveller 3:ed09f95739df 82 {
vtraveller 4:d70e37f6c6bd 83 pc.printf("\n\rSTART\n\r");
vtraveller 5:6c9ee7e3a20c 84
vtraveller 5:6c9ee7e3a20c 85 // Take MCP out of reset to show its backlight
vtraveller 6:a6be2aede8f2 86 //pc.printf("mcp23017.config(0,1,0);\n\r");
vtraveller 6:a6be2aede8f2 87 //mcp23017.config(0,1,0);
vtraveller 6:a6be2aede8f2 88 //wait(0.5);
vtraveller 5:6c9ee7e3a20c 89
vtraveller 6:a6be2aede8f2 90 pc.printf("\n\rInitialise LCD\n\r");
vtraveller 6:a6be2aede8f2 91 lcd.begin(16,2);
vtraveller 6:a6be2aede8f2 92
vtraveller 5:6c9ee7e3a20c 93 pc.printf("\n\rEntering key tracking loop\n\r");
vtraveller 4:d70e37f6c6bd 94 while (true)
vtraveller 4:d70e37f6c6bd 95 {
vtraveller 4:d70e37f6c6bd 96 loop();
vtraveller 4:d70e37f6c6bd 97 wait(0.2);
vtraveller 5:6c9ee7e3a20c 98 }
wim 0:88d87b1c1f8b 99 }