standalone sx1276 demo program

Dependencies:   SX1276Lib mbed

Fork of SX1276_GPS by CaryCoders

Committer:
vtraveller
Date:
Sat Aug 02 14:16:30 2014 +0000
Revision:
5:6c9ee7e3a20c
Parent:
4:d70e37f6c6bd
Child:
6:a6be2aede8f2
Improved pull-up resisitor code

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 4:d70e37f6c6bd 9 Adafruit_RGBLCDShield lcd(mcp23017);
wim 0:88d87b1c1f8b 10
vtraveller 3:ed09f95739df 11 #define RED 0x1
vtraveller 3:ed09f95739df 12 #define YELLOW 0x3
vtraveller 3:ed09f95739df 13 #define GREEN 0x2
vtraveller 3:ed09f95739df 14 #define TEAL 0x6
vtraveller 3:ed09f95739df 15 #define BLUE 0x4
vtraveller 3:ed09f95739df 16 #define VIOLET 0x5
vtraveller 3:ed09f95739df 17 #define WHITE 0x7
vtraveller 3:ed09f95739df 18
vtraveller 3:ed09f95739df 19 // Allows to set the backlight, if the LCD backpack is used
vtraveller 3:ed09f95739df 20 void SetBacklight(unsigned char status)
vtraveller 3:ed09f95739df 21 {
vtraveller 3:ed09f95739df 22 pc.printf("Backlight: %i\n\r", status);
vtraveller 3:ed09f95739df 23
vtraveller 3:ed09f95739df 24 mcp23017.digitalWrite(8, (~(status >> 2) & 0x1));
vtraveller 3:ed09f95739df 25 mcp23017.digitalWrite(7, (~(status >> 1) & 0x1));
vtraveller 3:ed09f95739df 26 mcp23017.digitalWrite(6, (~status & 0x1));
vtraveller 3:ed09f95739df 27 }
wim 0:88d87b1c1f8b 28
vtraveller 4:d70e37f6c6bd 29 void loop()
vtraveller 3:ed09f95739df 30 {
vtraveller 4:d70e37f6c6bd 31 // set the cursor to column 0, line 1
vtraveller 4:d70e37f6c6bd 32 // (note: line 1 is the second row, since counting begins with 0):
vtraveller 4:d70e37f6c6bd 33 lcd.setCursor(0, 1);
vtraveller 4:d70e37f6c6bd 34
vtraveller 4:d70e37f6c6bd 35 uint8_t buttons = lcd.readButtons();
vtraveller 4:d70e37f6c6bd 36
vtraveller 4:d70e37f6c6bd 37 if (buttons)
vtraveller 4:d70e37f6c6bd 38 {
vtraveller 4:d70e37f6c6bd 39 lcd.clear();
vtraveller 4:d70e37f6c6bd 40 lcd.setCursor(0,0);
vtraveller 4:d70e37f6c6bd 41
vtraveller 4:d70e37f6c6bd 42 if (buttons & BUTTON_UP)
vtraveller 4:d70e37f6c6bd 43 {
vtraveller 4:d70e37f6c6bd 44 pc.printf("UP ");
vtraveller 4:d70e37f6c6bd 45
vtraveller 4:d70e37f6c6bd 46 lcd.printf("UP ");
vtraveller 4:d70e37f6c6bd 47 lcd.setBacklight(RED);
vtraveller 4:d70e37f6c6bd 48 }
vtraveller 4:d70e37f6c6bd 49
vtraveller 4:d70e37f6c6bd 50 if (buttons & BUTTON_DOWN)
vtraveller 4:d70e37f6c6bd 51 {
vtraveller 4:d70e37f6c6bd 52 pc.printf("DOWN ");
vtraveller 4:d70e37f6c6bd 53
vtraveller 4:d70e37f6c6bd 54 lcd.printf("DOWN ");
vtraveller 4:d70e37f6c6bd 55 lcd.setBacklight(YELLOW);
vtraveller 4:d70e37f6c6bd 56 }
vtraveller 4:d70e37f6c6bd 57
vtraveller 4:d70e37f6c6bd 58 if (buttons & BUTTON_LEFT)
vtraveller 4:d70e37f6c6bd 59 {
vtraveller 4:d70e37f6c6bd 60 pc.printf("LEFT ");
vtraveller 4:d70e37f6c6bd 61
vtraveller 4:d70e37f6c6bd 62 lcd.printf("LEFT ");
vtraveller 4:d70e37f6c6bd 63 lcd.setBacklight(GREEN);
vtraveller 4:d70e37f6c6bd 64 }
vtraveller 4:d70e37f6c6bd 65
vtraveller 4:d70e37f6c6bd 66 if (buttons & BUTTON_RIGHT)
vtraveller 4:d70e37f6c6bd 67 {
vtraveller 4:d70e37f6c6bd 68 pc.printf("RIGHT ");
vtraveller 4:d70e37f6c6bd 69
vtraveller 4:d70e37f6c6bd 70 lcd.printf("RIGHT ");
vtraveller 4:d70e37f6c6bd 71 lcd.setBacklight(TEAL);
vtraveller 4:d70e37f6c6bd 72 }
vtraveller 4:d70e37f6c6bd 73
vtraveller 4:d70e37f6c6bd 74 if (buttons & BUTTON_SELECT)
vtraveller 4:d70e37f6c6bd 75 {
vtraveller 4:d70e37f6c6bd 76 pc.printf("SELECT ");
vtraveller 4:d70e37f6c6bd 77
vtraveller 4:d70e37f6c6bd 78 lcd.printf("SELECT ");
vtraveller 4:d70e37f6c6bd 79 lcd.setBacklight(VIOLET);
vtraveller 4:d70e37f6c6bd 80 }
vtraveller 4:d70e37f6c6bd 81 }
vtraveller 3:ed09f95739df 82 }
vtraveller 3:ed09f95739df 83
vtraveller 3:ed09f95739df 84 int main()
vtraveller 3:ed09f95739df 85 {
vtraveller 4:d70e37f6c6bd 86 pc.printf("\n\rSTART\n\r");
vtraveller 5:6c9ee7e3a20c 87
vtraveller 5:6c9ee7e3a20c 88 // Take MCP out of reset to show its backlight
vtraveller 3:ed09f95739df 89 pc.printf("mcp23017.config(0,1,0);\n\r");
vtraveller 3:ed09f95739df 90 mcp23017.config(0,1,0);
vtraveller 5:6c9ee7e3a20c 91
vtraveller 5:6c9ee7e3a20c 92 wait(0.5);
vtraveller 5:6c9ee7e3a20c 93
vtraveller 5:6c9ee7e3a20c 94 pc.printf("\n\rInitialise LCD\n\r");
vtraveller 5:6c9ee7e3a20c 95 lcd.begin(16,2);
vtraveller 5:6c9ee7e3a20c 96
vtraveller 5:6c9ee7e3a20c 97 pc.printf("\n\rShow a letter\n\r");
vtraveller 5:6c9ee7e3a20c 98 lcd._putc('A');
vtraveller 5:6c9ee7e3a20c 99
vtraveller 3:ed09f95739df 100 wait(0.5);
wim 0:88d87b1c1f8b 101
vtraveller 5:6c9ee7e3a20c 102 pc.printf("\n\rPrint Hello World\n\r");
vtraveller 4:d70e37f6c6bd 103 lcd.printf("Hello, world!");
vtraveller 4:d70e37f6c6bd 104 lcd.setBacklight(GREEN);
wim 0:88d87b1c1f8b 105
vtraveller 5:6c9ee7e3a20c 106 wait(0.5);
vtraveller 5:6c9ee7e3a20c 107
vtraveller 5:6c9ee7e3a20c 108 pc.printf("\n\rEntering key tracking loop\n\r");
vtraveller 4:d70e37f6c6bd 109 while (true)
vtraveller 4:d70e37f6c6bd 110 {
vtraveller 4:d70e37f6c6bd 111 loop();
vtraveller 4:d70e37f6c6bd 112 wait(0.2);
vtraveller 5:6c9ee7e3a20c 113 }
wim 0:88d87b1c1f8b 114 }