Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FXOS8700Q FastPWM
Diff: main.cpp
- Revision:
- 7:a32766b96d91
- Parent:
- 5:cee5f898b350
- Child:
- 8:ec3c634390c7
--- a/main.cpp Thu Sep 19 14:09:39 2019 +0000 +++ b/main.cpp Thu Sep 19 14:12:30 2019 +0000 @@ -10,83 +10,20 @@ DigitalOut ledblue(LED_BLUE); DigitalOut ledgreen(LED_GREEN); InterruptIn button(SW2); - - - -Ticker Theticker; -volatile char c='x'; -volatile int color=0; -void PrintColor(void) +AnalogIn ain(A0); +DigitalOut dout(LED1); + +int main(void) { - switch(c) + while (true) { - case 'r': - pc.printf("Red"); - break; - case 'g': - pc.printf("Green"); - break; - case 'b': - pc.printf("Blue"); - break; - case 'd': - pc.printf("Disco"); - break; - default: - pc.printf("Unknown"); + // test the voltage on the initialized analog pin + // and if greater than 0.3 * VCC set the digital pin + // to a logic 1 otherwise a logic 0 + + // print the percentage and 16 bit normalized values + pc.printf("percentage: %3.3f%%\n", ain.read()*100.0f); + pc.printf("normalized: 0x%04X \n", ain.read_u16()); + wait_ms(1000); } } -void Take_Measurement(void) -{ - if (c=='r') - { - ledred=!ledred; - } - else if (c=='g') - { - ledgreen=!ledgreen; - } - else if (c=='b') - { - ledblue=!ledblue; - } - else if (c=='d') - { - color+=1; - ledred=!ledred; - if (color%2==0) - { - ledgreen=!ledgreen; - } - if (color%4==0) - { - ledblue=!ledblue; - } - } - else - { - ledred=1; - ledgreen=1; - ledblue=1; - } -} - -int main() -{ - button.fall(&PrintColor); - ledred=1; - ledgreen=1; - ledblue=1; - Theticker.attach(Take_Measurement,0.05); - int countr; - pc.baud(115200); - pc.printf("\r\nStarting...\r\n\r\n"); - pc.printf("Enter the color that has to blink:\r\n"); - c=pc.getc(); - pc.printf("Color picked: '%c'\r\nNow counting so the system does something:\r\n",c); - while (true) { - countr+=1; - pc.printf("%i\r\n",countr); - wait_ms(500); - } -}