![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Keg sharing system
Dependencies: 4DGL-uLCD-SE TextLCD mbed
Diff: main.cpp
- Revision:
- 5:571cd0eea9be
- Parent:
- 4:bcb5be37a0e1
--- a/main.cpp Fri Dec 09 02:08:46 2016 +0000 +++ b/main.cpp Fri Dec 09 03:18:03 2016 +0000 @@ -17,30 +17,40 @@ I2C i2c ( p9 , p10 ) ; Mpr121 keypad ( & i2c , Mpr121::ADD_VSS ) ; +#define LCD_ON 1 + // LCD ( tx , rx , reset ) -//uLCD_4DGL lcd ( p28 , p27 , p5 ) ; +#if LCD_ON +uLCD_4DGL lcd ( p28 , p27 , p5 ) ; +#endif // flow meter InterruptIn pulse_interrupt ( p11 ) ; int unsigned pulse_count ( 0 ) ; float pulse_milliLiters ( ) { - return ( ( float ) pulse_count ) / 0.450f ; + float const factor ( 300.0f / 206.0f ) ; + return ( ( float ) pulse_count * factor ) / 0.450f ; } void pulse ( ) { ++ pulse_count ; -// lcd.locate ( 4 , 8 ) ; -// lcd.printf ( "%f mL" , pulse_milliLiters ( ) ) ; + led4 = ! led4 ; +#if LCD_ON + lcd.locate ( 4 , 8 ) ; + lcd.printf ( "%f mL" , pulse_milliLiters ( ) ) ; +#endif } void read_pin ( ) { -// lcd.filled_rectangle ( 0 , 0 , 128 , 128 , BLACK ) ; -// lcd.locate ( 4 , 6 ) ; -// lcd.printf ( "Enter PIN" ) ; -// lcd.locate ( 4 , 7 ) ; -// lcd.printf ( "on keypad" ) ; +#if LCD_ON + lcd.filled_rectangle ( 0 , 0 , 128 , 128 , BLACK ) ; + lcd.locate ( 4 , 6 ) ; + lcd.printf ( "Enter PIN" ) ; + lcd.locate ( 4 , 7 ) ; + lcd.printf ( "on keypad" ) ; +#endif } enum @@ -75,8 +85,10 @@ case 0x100 : // DONE com.printf ( "a%020f\n" , pulse_milliLiters ( ) ) ; -// lcd.locate ( 0 , 10 ) ; -// lcd.printf ( "Done pouring." ) ; +#if LCD_ON + lcd.locate ( 0 , 10 ) ; + lcd.printf ( "Done pouring." ) ; +#endif pulse_count = 0 ; read_pin ( ) ; return ; @@ -93,9 +105,11 @@ case 0x800 : pin_value = pin_value * 10 + 9 ; break ; // 9 } -// lcd.locate ( pin_col + pin_count , pin_row ) ; -// lcd.printf ( "*" ) ; - +#if LCD_ON + lcd.locate ( pin_col + pin_count , pin_row ) ; + lcd.printf ( "*" ) ; +#endif + if ( pin_count == 3 ) { com.printf ( "p%04d\n\r" , pin_value ) ; // transmit pin @@ -105,33 +119,40 @@ char readbuffer [ 2 ] ; com.gets ( readbuffer , 2 ) ; // receive verification -// lcd.locate ( 4 , 6 ) ; - +#if LCD_ON + lcd.locate ( 4 , 6 ) ; +#endif switch ( readbuffer [ 0 ] ) // parse verification { case '0' : // INVALID -// lcd.filled_rectangle ( 0 , 0 , 128 , 128 , RED ) ; -// lcd.locate ( 4 , 5 ) ; -// lcd.printf ( "INVALID PIN" ) ; led3 = ! led3 ; -// wait_ms ( 1024 ) ; +#if LCD_ON + lcd.filled_rectangle ( 0 , 0 , 128 , 128 , RED ) ; + lcd.locate ( 4 , 5 ) ; + lcd.printf ( "INVALID PIN" ) ; + wait_ms ( 1024 ) ; +#endif read_pin ( ) ; break ; case '1' : // VALID -// lcd.filled_rectangle ( 0 , 0 , 128 , 128 , GREEN ) ; -// lcd.printf ( "Pour beer" ) ; -// lcd.locate ( 4 , 8 ) ; led4 = ! led4 ; char buffer [ 6 ] ; com.gets ( buffer , sizeof ( buffer ) ) ; -// lcd.locate ( 4 , 10 ) ; -// lcd.printf ( "Current owed: $%s" , buffer ) ; +#if LCD_ON + lcd.filled_rectangle ( 0 , 0 , 128 , 128 , GREEN ) ; + lcd.printf ( "Pour beer" ) ; +// lcd.locate ( 4 , 8 ) ; + lcd.locate ( 4 , 10 ) ; + lcd.printf ( "Current owed: $%s" , buffer ) ; +#endif break ; default: // ERROR -// lcd.filled_rectangle ( 0 , 0 , 128 , 128 , YELLOW ) ; -// lcd.printf ( "TRANSMISSION ERROR" ) ; +#if LCD_ON + lcd.filled_rectangle ( 0 , 0 , 128 , 128 , YELLOW ) ; + lcd.printf ( "TRANSMISSION ERROR" ) ; +#endif led2 = ! led2 ; exit ( 1 ) ; break ;