
Instrumentation Lab
main.cpp@0:acbface38eff, 2019-05-02 (annotated)
- Committer:
- MattGow
- Date:
- Thu May 02 19:10:33 2019 +0000
- Revision:
- 0:acbface38eff
Rev1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MattGow | 0:acbface38eff | 1 | #include "mbed.h" |
MattGow | 0:acbface38eff | 2 | #include "C12832.h" |
MattGow | 0:acbface38eff | 3 | |
MattGow | 0:acbface38eff | 4 | InterruptIn button(p14); |
MattGow | 0:acbface38eff | 5 | DigitalOut led(LED1); |
MattGow | 0:acbface38eff | 6 | DigitalOut flash(LED4); |
MattGow | 0:acbface38eff | 7 | C12832 lcd(p5, p7 ,p6, p8, p11); // initilize lcd |
MattGow | 0:acbface38eff | 8 | Timer debounce; |
MattGow | 0:acbface38eff | 9 | |
MattGow | 0:acbface38eff | 10 | int joystick; // inilize integer value from p14 |
MattGow | 0:acbface38eff | 11 | |
MattGow | 0:acbface38eff | 12 | void flip() { |
MattGow | 0:acbface38eff | 13 | led = !led; // toggles the led, when pressing a button connects ground to p14. |
MattGow | 0:acbface38eff | 14 | } |
MattGow | 0:acbface38eff | 15 | |
MattGow | 0:acbface38eff | 16 | int main() { |
MattGow | 0:acbface38eff | 17 | debounce.start(); |
MattGow | 0:acbface38eff | 18 | button.rise(&flip); // attach the function address to the rising edge (of p14) |
MattGow | 0:acbface38eff | 19 | while(1) { // wait around, interrupts will interrupt this. |
MattGow | 0:acbface38eff | 20 | flash = !flash; // this just turns LED4 on and off every quarter second |
MattGow | 0:acbface38eff | 21 | joystick = button; // ties joystick value to p14 condition |
MattGow | 0:acbface38eff | 22 | if (joystick==1){ // test value of joystick |
MattGow | 0:acbface38eff | 23 | lcd.cls(); // clear lcd screen |
MattGow | 0:acbface38eff | 24 | lcd.locate(2,2); // sets start location for print text |
MattGow | 0:acbface38eff | 25 | lcd.printf("joystick pressed"); // print instruction |
MattGow | 0:acbface38eff | 26 | wait(0.25); |
MattGow | 0:acbface38eff | 27 | } |
MattGow | 0:acbface38eff | 28 | else{ |
MattGow | 0:acbface38eff | 29 | lcd.cls(); // clear lcd screen |
MattGow | 0:acbface38eff | 30 | lcd.locate(2,12); // sets start location for print text |
MattGow | 0:acbface38eff | 31 | lcd.printf("joystick is not pressed "); |
MattGow | 0:acbface38eff | 32 | wait(0.25); // this is the instruction to wait for a quarter second |
MattGow | 0:acbface38eff | 33 | if (debounce.read_ms()>10) |
MattGow | 0:acbface38eff | 34 | debounce.reset(); |
MattGow | 0:acbface38eff | 35 | } |
MattGow | 0:acbface38eff | 36 | |
MattGow | 0:acbface38eff | 37 | } |
MattGow | 0:acbface38eff | 38 | } |