homework 7

Dependencies:   mbed-rtos mbed C12832_lcd LM75B

main.cpp

Committer:
gatedClock
Date:
2013-08-30
Revision:
0:fcca4db7b32a
Child:
1:9188d4668a88

File content as of revision 0:fcca4db7b32a:

/*----------------------------------------------//------------------------------
    student   : m-moore
    class     : rtos
    directory : RTOS_HW_04
    file      : main.cpp
----description---------------------------------//------------------------------
    Joystick-Controlled Metronome
    
    features:
    1. joystick-controlled.
    2. turns off after one minute.
    3. ISR's for all joystick inputs.
    4. joystick debounce.
    5. LED and LCD displays.
    6. BPM rate adjustable even when metronome is off.
    7. BPM saturates at defined lower/upper bounds.

    controls:
    1. joystick-left   - increase metronome rate.
    2. joystick-right  - decrease metronome rate.
    3. joystick-down   - start metronome.
    4. joystick-up     - stop metronome.
    5. joystick-center - set metronome to 60BPM.
    
    notes:
    1. adding the mbed-rtos library to this project prevents the
       LED from blinking and the LCD from displaying, even if
       there is no #include "rtos.h" statement.
    2. i was considering having the BPM up/down ISRs set up self-
       ending threads for continuous button press for rapid rate
       change, but again, rtos.h was causing trouble.
    3. I'm making use of disable-interrupts for bounce suppression.
       this could microscopically delay the metronome while its
       BPM is being adjusted, since I can't turn off only the
       interrupt involved with joystick input.
    
    testing:
    1. start metronome - verify it blinks, and stops after a minute.
    2. stop  metronome - verity it stops metronome.
    3. verify display indicates ON and OFF state.
    4. verify display indicates BPM rate.
    5. operate left/right joystick, inspect for BPM jumps (bounce).
    6. verify lower/upper BPM bounds.  (only lower-bound tested).
-----includes-----------------------------------//----------------------------*/
    #include "mbed.h"                           // mbed class.
//  #include "rtos.h"
    #include "C12832_lcd.h"                     // LCD class.
//---defines------------------------------------//------------------------------
    #define LCD1 lcd.locate(0, 0);              // LCD line 1.
    #define LCD2 lcd.locate(0,11);              // LCD line 2.
    #define LCD3 lcd.locate(0,22);              // LCD line 3.

//--global_definitions--------------------------//------------------------------
//--global_variables----------------------------//------------------------------ 

//--global_instances----------------------------//------------------------------ 
    C12832_LCD   lcd;                           // LCD object.
    
    InterruptIn  iJoyStickUp    (p15);          // joystick up rising edge.
    InterruptIn  iJoyStickDown  (p12);          // joystick down rising edge.
    InterruptIn  iJoyStickLeft  (p13);          // joystick left rising edge.
    InterruptIn  iJoyStickRight (p16);          // joystick right rising edge.
    InterruptIn  iJoyStickCenter(p14);          // 1 if joystick middle pressed.

    DigitalOut  led3(LED1);                     // leftmost LED.
    
    Ticker      tickerMetronome;                // blinking LED.
    Ticker      tickerLCD;                      // display ticker.
    Timeout     timeoutDutyCycle;               // LED duty cycle delay.
    Timeout     timeoutMetronome;
//-------prototypes-----------------------------//------------------------------

//==============================================//==============================
    int main(void) 
    {
      iJoyStickUp.rise   (&ISR_up);
      iJoyStickDown.rise (&ISR_down);
      iJoyStickLeft.rise (&ISR_left); 
      iJoyStickRight.rise(&ISR_right);
      iJoyStickCenter.rise(&ISR_center); 
      
      initialization();                         // initialize variables.
      

      
      while(1)                                  // all timer/interrupt driven.
      {
        wait(10.0);
      }
    }       
/*----------------------------------------------//----------------------------*/
    void initialization(void)                   // program initializations.
    {

    }
/*----------------------------------------------//----------------------------*/