AirsoftTimer software based on mbed

Dependencies:   mbed TextLCD keypad

main.cpp

Committer:
sillevl
Date:
2014-12-12
Revision:
3:ce34dfe2463b
Parent:
2:f8e46daca111
Child:
4:2c91c9eccf3a

File content as of revision 3:ce34dfe2463b:

#include "mbed.h"
#include "cmsis_os.h"


//#include "Airsofttimer.h"
#include "TextLCD.h"


struct product {
    int weight;
    float price;
} ;



DigitalOut heartbeatLed(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

PwmOut buzzer(P2_3);

DigitalOut leda(P2_4);
DigitalOut ledb(P2_5);

DigitalOut col1(P0_16);
DigitalOut col2(P0_17);
DigitalOut col3(P0_18);

DigitalIn row1(P0_8);
DigitalIn row2(P0_9);
DigitalIn row3(P0_10);
DigitalIn row4(P0_11);

DigitalIn button(P0_5);
DigitalIn key(P0_4);

int colCounter = 1;

//keyboardRowPins = {P0_8 , P0_9 , P0_10, P0_11};              // ROWS=P0.8 -> P0.11
//keyboardColPins = {P0_16, P0_17, P0_18};                     // COLS=P0.16 -> P0.18

void heartbeatThread(void const *args)
{
    while(true) {
        heartbeatLed = 1;
        leda = ledb = 1;
        osDelay(10);
        heartbeatLed = 0;
        leda = ledb = 0;
        osDelay(300);
        heartbeatLed = 1;
        leda = ledb = 1;
        osDelay(10);
        heartbeatLed = 0;
        leda = ledb = 0;
        osDelay(680);
    }
}

osThreadDef(heartbeatThread, osPriorityNormal, DEFAULT_STACK_SIZE);

int main()
{
    int tone =2300;
    osThreadCreate(osThread(heartbeatThread), NULL);
    TextLCD lcd(P1_30, P1_31, P0_23, P0_24, P0_25, P0_26,  TextLCD::LCD20x4); // rs, e, d4-d7
    buzzer.period_us(1/2400);

    while(1) {

        lcd.locate(0,1);
        lcd.printf("  - AirsoftTimer - ");
        lcd.locate(0,3);
        lcd.printf("Prototype       V0.3");

        tone = tone +20;
        if(tone > 2500) tone = 2300;
        if(!button) {
            buzzer.period_us(1000000/tone);
            buzzer = 0.5;
        } else {
            buzzer = 0.0;
        }

        osDelay(10);
    }
}



/*
char degree[8] = {0x02,0x05,0x05,0x02,0x00,0x00,0x00,0x00};

lcd.putcustomChar(1,degree,0x01,12,0);

lcd.printf("C");
*/