Working Menu, additions to be made

Dependencies:   mbed

main.cpp

Committer:
25574069
Date:
2021-12-07
Revision:
1:a87075699085
Parent:
0:d4d7e882c87d
Child:
2:d3676e11e2c6

File content as of revision 1:a87075699085:

/*
Code for a IoT Temperature reading device.
Acknowledgements to xxxxx
**/

#include "mbed.h"
#include "N5110.h"
#include "Joystick.h"

//Defines
AnalogIn pot(PTB2);

//LCD Sprite:
//       rows,cols
int sprite[8][5] =   {
    { 0,0,1,0,0 },
    { 0,1,1,1,0 },
    { 0,0,1,0,0 },
    { 0,1,1,1,0 },
    { 1,1,1,1,1 },
    { 1,1,1,1,1 },
    { 1,1,0,1,1 },
    { 1,1,0,1,1 },
};

//Objects
Ticker bl_ticker;

// Global Volatile Interrupt flags
volatile int g_bl_timer_flag;

// Setup interrupts
void bl_timer_isr();

//Data
float bright;

//Pinouts
//        SCE, RST, D/C, MOSI,SCLK,LED
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);  // K64F - pwr from 3V3
//                y     x     button
Joystick joystick(PTB10,PTB11,PTC16);


int main() {
    
    //Initialise devices
    lcd.init();
    lcd.setContrast(0.4);
    
    //Set up ticker (time in seconds)
    bl_ticker.attach(&bl_timer_isr,0.01);
    
    while (1){
        
        //Read pot value and assign to variable
        if(pot > 0.1f) {
            bright = 0.1;
        } if(pot > 0.2f) {
            bright = 0.2;
        } if (pot > 0.3f) {
            bright = 0.3;
        } if (pot > 0.4f) {
            bright = 0.4;
        } if (pot > 0.5f) {
            bright = 0.5;
        } if(pot > 0.6f) {
            bright = 0.6;
        } if(pot > 0.7f) {
            bright = 0.7;
        } if (pot > 0.8f) {
            bright = 0.8;
        } if (pot > 0.9f) {
            bright = 0.9;
        } if (pot > 1.0f) {
            bright = 1.0;
        }  
       
        //Check interrupt flags:
        //LCD backlight interrupt
        if (g_bl_timer_flag) {
           g_bl_timer_flag = 0;   //if flag is set, clear

           lcd.setBrightness(bright); //set brightness based on pot value
        }
                         
    }
}

// time-triggered interrupt for red
void bl_timer_isr()
{
    g_bl_timer_flag = 1;   // set flag in ISR
}
 
//Had multiple issues where code isn't changed but comments are added, suddenly defines don't work anymore "not defined"