standalone sx1276 demo program

Dependencies:   SX1276Lib mbed

Fork of SX1276_GPS by CaryCoders

main.cpp

Committer:
vtraveller
Date:
2014-08-03
Revision:
7:d087e901b74b
Parent:
6:a6be2aede8f2
Child:
9:1501fb01ded6

File content as of revision 7:d087e901b74b:

#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);
    
// 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()
{
    static int count = 0;
    
    uint8_t buttons = lcd.readButtons();

    if (buttons)
    {
        count = 0;
        
        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 ");            
        }
    }
    else
    {
        lcd.setCursor(0,1);
        lcd.printf("Waiting... %i",count++);
    }
}

int main()
{    
    pc.printf("\n\rInitialise LCD\n\r");    
    lcd.begin(16,2);

    lcd.printf("AdaFruit RGB LCD Shield");            
    pc.printf("\n\rEntering key tracking loop\n\r");
    while (true)
    {
        loop();
        wait(0.2);
    }    
}