Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Laser-Distance by
main.cpp@11:b68be9bd5754, 2018-10-01 (annotated)
- Committer:
- KStefan
- Date:
- Mon Oct 01 09:17:01 2018 +0000
- Revision:
- 11:b68be9bd5754
- Parent:
- 10:f727c310c86f
- Child:
- 12:b436e51e86a8
Interrupt auf fallende Flanke, PullUp konfiguriert
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 | 11:b68be9bd5754 | 6 | InterruptIn 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 orange(); |
KStefan | 11:b68be9bd5754 | 16 | |
KStefan | 11:b68be9bd5754 | 17 | void blue(){ |
KStefan | 11:b68be9bd5754 | 18 | count_b++; |
KStefan | 11:b68be9bd5754 | 19 | } |
KStefan | 11:b68be9bd5754 | 20 | void green() { |
KStefan | 11:b68be9bd5754 | 21 | count_g++; |
KStefan | 11:b68be9bd5754 | 22 | } |
KStefan | 11:b68be9bd5754 | 23 | |
andcor02 | 0:80032665d37e | 24 | int main() |
andcor02 | 0:80032665d37e | 25 | { |
KStefan | 11:b68be9bd5754 | 26 | sw_o.mode(PullUp); |
KStefan | 11:b68be9bd5754 | 27 | sw_b.mode(PullUp); |
KStefan | 11:b68be9bd5754 | 28 | sw_g.mode(PullUp); |
KStefan | 11:b68be9bd5754 | 29 | sw_o.fall(&orange); |
KStefan | 11:b68be9bd5754 | 30 | sw_b.fall(&blue); |
KStefan | 11:b68be9bd5754 | 31 | sw_g.fall(&green); |
KStefan | 11:b68be9bd5754 | 32 | |
KStefan | 11:b68be9bd5754 | 33 | |
KStefan | 9:a4a4f8cc4019 | 34 | lcd.printf(0, "Red Blue Green\r"); // Parameter von printf auf LCD: Zeilennummer (0 or 1), string |
KStefan | 9:a4a4f8cc4019 | 35 | while(1) { |
KStefan | 8:0f74264cc38a | 36 | |
KStefan | 11:b68be9bd5754 | 37 | lcd.printf(1, "%d %d %d", count_o, count_b, count_g); |
KStefan | 8:0f74264cc38a | 38 | |
KStefan | 8:0f74264cc38a | 39 | myled = !myled; |
KStefan | 9:a4a4f8cc4019 | 40 | |
andcor02 | 0:80032665d37e | 41 | } |
KStefan | 11:b68be9bd5754 | 42 | } |
KStefan | 11:b68be9bd5754 | 43 | |
KStefan | 11:b68be9bd5754 | 44 | void orange() { |
KStefan | 11:b68be9bd5754 | 45 | count_o++; |
andcor02 | 2:587b4d7444d1 | 46 | } |