standalone sx1276 demo program

Dependencies:   SX1276Lib mbed

Fork of SX1276_GPS by CaryCoders

main.cpp

Committer:
vtraveller
Date:
2014-08-02
Revision:
6:a6be2aede8f2
Parent:
5:6c9ee7e3a20c
Child:
7:d087e901b74b

File content as of revision 6:a6be2aede8f2:

#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,pc);
    
// Allows to set the backlight, if the LCD backpack is used
void SetBacklight(unsigned char status)
{
    pc.printf("Backlight: %i\n\r", status);
    
    mcp23017.digitalWrite(8, (~(status >> 2) & 0x1));
    mcp23017.digitalWrite(7, (~(status >> 1) & 0x1));
    mcp23017.digitalWrite(6, (~status & 0x1));
}

void loop()
{
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(10, 1);
    
    //lcd.cursor();
    //lcd.blink();
        
    uint8_t buttons = lcd.readButtons();
    
    lcd.setBacklight(buttons ? 1 : 0);    
    
    if (buttons)
    {
        lcd.clear();
        lcd.setCursor(0,0);
        
        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.setCursor(0,0);
    lcd._putc('A');
    
    lcd.display();
}

int main()
{    
    pc.printf("\n\rSTART\n\r");

    // Take MCP out of reset to show its backlight
    //pc.printf("mcp23017.config(0,1,0);\n\r");
    //mcp23017.config(0,1,0);    
    //wait(0.5);

    pc.printf("\n\rInitialise LCD\n\r");    
    lcd.begin(16,2);
        
    pc.printf("\n\rEntering key tracking loop\n\r");
    while (true)
    {
        loop();
        wait(0.2);
    }    
}