Code-Basis für Programm zum Taster-Entprellen
Fork of Laser-Distance by
main.cpp@12:b436e51e86a8, 2018-10-01 (annotated)
- Committer:
- KStefan
- Date:
- Mon Oct 01 11:21:17 2018 +0000
- Revision:
- 12:b436e51e86a8
- Parent:
- 11:b68be9bd5754
- Child:
- 13:87f9e63b2cfa
Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andcor02 | 0:80032665d37e | 1 | #include "mbed.h" |
KStefan | 8:0f74264cc38a | 2 | #include "SB1602E.h" |
andcor02 | 5:1fca2683ae6f | 3 | #define USE_I2C_2V8 |
andcor02 | 0:80032665d37e | 4 | |
KStefan | 9:a4a4f8cc4019 | 5 | DigitalOut myled(P0_8); // 7=rot, 8=grün, 9=blau |
KStefan | 12:b436e51e86a8 | 6 | DigitalIn sw_o(P0_12); |
KStefan | 11:b68be9bd5754 | 7 | InterruptIn sw_b(P0_13); |
KStefan | 11:b68be9bd5754 | 8 | InterruptIn sw_g(P0_14); |
andcor02 | 5:1fca2683ae6f | 9 | |
KStefan | 9:a4a4f8cc4019 | 10 | I2C i2c_disp(P0_5, P0_4); // SDA, SCL auf LPC11U24 |
KStefan | 9:a4a4f8cc4019 | 11 | SB1602E lcd(i2c_disp); |
andcor02 | 5:1fca2683ae6f | 12 | |
KStefan | 9:a4a4f8cc4019 | 13 | int count_o, count_b, count_g = 0; |
andcor02 | 0:80032665d37e | 14 | |
KStefan | 11:b68be9bd5754 | 15 | void blue(){ |
KStefan | 11:b68be9bd5754 | 16 | count_b++; |
KStefan | 11:b68be9bd5754 | 17 | } |
KStefan | 11:b68be9bd5754 | 18 | void green() { |
KStefan | 11:b68be9bd5754 | 19 | count_g++; |
KStefan | 11:b68be9bd5754 | 20 | } |
KStefan | 11:b68be9bd5754 | 21 | |
andcor02 | 0:80032665d37e | 22 | int main() |
andcor02 | 0:80032665d37e | 23 | { |
KStefan | 11:b68be9bd5754 | 24 | sw_o.mode(PullUp); |
KStefan | 11:b68be9bd5754 | 25 | sw_b.mode(PullUp); |
KStefan | 11:b68be9bd5754 | 26 | sw_g.mode(PullUp); |
KStefan | 12:b436e51e86a8 | 27 | |
KStefan | 11:b68be9bd5754 | 28 | sw_b.fall(&blue); |
KStefan | 11:b68be9bd5754 | 29 | sw_g.fall(&green); |
KStefan | 12:b436e51e86a8 | 30 | wait(0.2); |
KStefan | 11:b68be9bd5754 | 31 | |
KStefan | 12:b436e51e86a8 | 32 | int sw_o_old = 0; |
KStefan | 12:b436e51e86a8 | 33 | int sw_o_new; |
KStefan | 11:b68be9bd5754 | 34 | |
KStefan | 9:a4a4f8cc4019 | 35 | lcd.printf(0, "Red Blue Green\r"); // Parameter von printf auf LCD: Zeilennummer (0 or 1), string |
KStefan | 9:a4a4f8cc4019 | 36 | while(1) { |
KStefan | 12:b436e51e86a8 | 37 | sw_o_new = sw_o; |
KStefan | 12:b436e51e86a8 | 38 | if ((sw_o_new==0) && (sw_o_old==1)) count_o++; // fallende Flanke: old=1 & new=0 |
KStefan | 12:b436e51e86a8 | 39 | sw_o_old = sw_o_new; |
KStefan | 12:b436e51e86a8 | 40 | lcd.printf(1,1, "%d %d %d", count_o, count_b, count_g); |
KStefan | 8:0f74264cc38a | 41 | |
KStefan | 8:0f74264cc38a | 42 | myled = !myled; |
KStefan | 9:a4a4f8cc4019 | 43 | |
andcor02 | 0:80032665d37e | 44 | } |
andcor02 | 2:587b4d7444d1 | 45 | } |