CaryCoders
/
demo_SX1276_standalone
standalone sx1276 demo program
Fork of SX1276_GPS by
main.cpp@3:ed09f95739df, 2014-08-02 (annotated)
- Committer:
- vtraveller
- Date:
- Sat Aug 02 12:39:25 2014 +0000
- Revision:
- 3:ed09f95739df
- Parent:
- 2:ac3b92ebf17a
- Child:
- 4:d70e37f6c6bd
snapshot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:88d87b1c1f8b | 1 | #include "mbed.h" |
wim | 0:88d87b1c1f8b | 2 | #include "MCP23017.h" |
wim | 0:88d87b1c1f8b | 3 | |
vtraveller | 3:ed09f95739df | 4 | Serial pc(SERIAL_TX, SERIAL_RX); |
wim | 0:88d87b1c1f8b | 5 | |
vtraveller | 3:ed09f95739df | 6 | MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40); |
wim | 0:88d87b1c1f8b | 7 | |
vtraveller | 3:ed09f95739df | 8 | #define RED 0x1 |
vtraveller | 3:ed09f95739df | 9 | #define YELLOW 0x3 |
vtraveller | 3:ed09f95739df | 10 | #define GREEN 0x2 |
vtraveller | 3:ed09f95739df | 11 | #define TEAL 0x6 |
vtraveller | 3:ed09f95739df | 12 | #define BLUE 0x4 |
vtraveller | 3:ed09f95739df | 13 | #define VIOLET 0x5 |
vtraveller | 3:ed09f95739df | 14 | #define WHITE 0x7 |
vtraveller | 3:ed09f95739df | 15 | |
vtraveller | 3:ed09f95739df | 16 | // Allows to set the backlight, if the LCD backpack is used |
vtraveller | 3:ed09f95739df | 17 | void SetBacklight(unsigned char status) |
vtraveller | 3:ed09f95739df | 18 | { |
vtraveller | 3:ed09f95739df | 19 | pc.printf("Backlight: %i\n\r", status); |
vtraveller | 3:ed09f95739df | 20 | |
vtraveller | 3:ed09f95739df | 21 | mcp23017.digitalWrite(8, (~(status >> 2) & 0x1)); |
vtraveller | 3:ed09f95739df | 22 | mcp23017.digitalWrite(7, (~(status >> 1) & 0x1)); |
vtraveller | 3:ed09f95739df | 23 | mcp23017.digitalWrite(6, (~status & 0x1)); |
vtraveller | 3:ed09f95739df | 24 | } |
wim | 0:88d87b1c1f8b | 25 | |
vtraveller | 3:ed09f95739df | 26 | void LED(bool bOn) |
vtraveller | 3:ed09f95739df | 27 | { |
vtraveller | 3:ed09f95739df | 28 | pc.printf("LED: %s\n\r", bOn ? "On" : "Off"); |
vtraveller | 3:ed09f95739df | 29 | //mcp23017.write(PORT_A, bOn ? 0x10 : 0xFF); |
vtraveller | 3:ed09f95739df | 30 | //mcp23017.write(PORT_B, bOn ? 0x10 : 0xFF); |
vtraveller | 3:ed09f95739df | 31 | } |
vtraveller | 3:ed09f95739df | 32 | |
vtraveller | 3:ed09f95739df | 33 | int main() |
vtraveller | 3:ed09f95739df | 34 | { |
vtraveller | 3:ed09f95739df | 35 | pc.printf("START\n\r"); |
wim | 0:88d87b1c1f8b | 36 | |
wim | 0:88d87b1c1f8b | 37 | // I2C init |
vtraveller | 3:ed09f95739df | 38 | //mcp23017.i2c.frequency(400000); |
wim | 0:88d87b1c1f8b | 39 | |
wim | 0:88d87b1c1f8b | 40 | // Port A is databus - Output |
vtraveller | 3:ed09f95739df | 41 | //mcp23017.direction(PORT_A, PORT_DIR_OUT); |
vtraveller | 3:ed09f95739df | 42 | |
wim | 0:88d87b1c1f8b | 43 | // Port B is controlbus - Output |
vtraveller | 3:ed09f95739df | 44 | //mcp23017.direction(PORT_B, PORT_DIR_OUT); |
vtraveller | 3:ed09f95739df | 45 | |
vtraveller | 3:ed09f95739df | 46 | pc.printf("mcp23017.config(0,1,0);\n\r"); |
vtraveller | 3:ed09f95739df | 47 | mcp23017.config(0,1,0); |
vtraveller | 3:ed09f95739df | 48 | wait(0.5); |
wim | 0:88d87b1c1f8b | 49 | |
vtraveller | 3:ed09f95739df | 50 | pc.printf("mcp23017.pinMode\n\r"); |
vtraveller | 3:ed09f95739df | 51 | mcp23017.pinMode(8, DIR_OUTPUT); |
vtraveller | 3:ed09f95739df | 52 | mcp23017.pinMode(7, DIR_OUTPUT); |
vtraveller | 3:ed09f95739df | 53 | mcp23017.pinMode(6, DIR_OUTPUT); |
vtraveller | 3:ed09f95739df | 54 | |
vtraveller | 3:ed09f95739df | 55 | SetBacklight(WHITE); |
vtraveller | 3:ed09f95739df | 56 | |
vtraveller | 3:ed09f95739df | 57 | wait(0.5); |
vtraveller | 1:45e2e7c0754d | 58 | pc.printf("MPC Init done\n\r"); |
wim | 0:88d87b1c1f8b | 59 | |
vtraveller | 3:ed09f95739df | 60 | LED(false); |
vtraveller | 3:ed09f95739df | 61 | LED(true); |
vtraveller | 3:ed09f95739df | 62 | |
vtraveller | 3:ed09f95739df | 63 | SetBacklight(RED); |
vtraveller | 3:ed09f95739df | 64 | pc.printf("FINISHED\n\r"); |
wim | 0:88d87b1c1f8b | 65 | } |