
dfg
Dependencies: TextLCD mbed-rtos mbed
Fork of TextLCD_HelloWorld_SuperTue by
main.cpp@4:6596cb2d1c90, 2015-01-23 (annotated)
- Committer:
- cad
- Date:
- Fri Jan 23 19:33:12 2015 +0000
- Revision:
- 4:6596cb2d1c90
- Parent:
- 3:39825a5cf7cf
- Child:
- 5:4eea67529466
CAD first test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 1:7418a52375a0 | 1 | // Hello World! for the TextLCD |
simon | 1:7418a52375a0 | 2 | |
simon | 0:334327d1a416 | 3 | #include "mbed.h" |
myren | 3:39825a5cf7cf | 4 | #include "TextLCD.h"//LCD bibliotek |
myren | 3:39825a5cf7cf | 5 | #include "rtos.h"//threading bibliotek |
simon | 0:334327d1a416 | 6 | |
myren | 3:39825a5cf7cf | 7 | TextLCD lcd_txt(p26, p25, p24, p23, p22, p21,TextLCD::LCD20x4); // rs, e, d4-d7 |
myren | 3:39825a5cf7cf | 8 | DigitalOut Led1 (LED1); |
myren | 3:39825a5cf7cf | 9 | DigitalOut Led2 (LED2); |
cad | 4:6596cb2d1c90 | 10 | DigitalOut Led3 (LED3); |
cad | 4:6596cb2d1c90 | 11 | DigitalOut Led4 (LED4); |
myren | 3:39825a5cf7cf | 12 | DigitalOut MyLed (p28); |
myren | 3:39825a5cf7cf | 13 | |
myren | 3:39825a5cf7cf | 14 | DigitalIn Btn1 (p27); |
myren | 3:39825a5cf7cf | 15 | |
cad | 4:6596cb2d1c90 | 16 | int count, count2,pos = 0; |
cad | 4:6596cb2d1c90 | 17 | bool NewPress = false; |
cad | 4:6596cb2d1c90 | 18 | char tempString[1]; |
cad | 4:6596cb2d1c90 | 19 | int code[5] = { 2, 5, 4, 7, 5 }; |
cad | 4:6596cb2d1c90 | 20 | |
myren | 3:39825a5cf7cf | 21 | |
myren | 3:39825a5cf7cf | 22 | |
simon | 0:334327d1a416 | 23 | |
myren | 3:39825a5cf7cf | 24 | void CheckBtn_thread(void const *args) |
myren | 3:39825a5cf7cf | 25 | { |
myren | 3:39825a5cf7cf | 26 | while (true) //tråd der scanner knapper |
myren | 3:39825a5cf7cf | 27 | { |
cad | 4:6596cb2d1c90 | 28 | // Led2 = !Led2; |
cad | 4:6596cb2d1c90 | 29 | Thread::wait(80); |
cad | 4:6596cb2d1c90 | 30 | count2++; |
myren | 3:39825a5cf7cf | 31 | |
cad | 4:6596cb2d1c90 | 32 | if (count2 == 10) |
cad | 4:6596cb2d1c90 | 33 | { |
cad | 4:6596cb2d1c90 | 34 | count2 = 0; |
cad | 4:6596cb2d1c90 | 35 | count++; |
cad | 4:6596cb2d1c90 | 36 | if (count == 10) |
cad | 4:6596cb2d1c90 | 37 | count = 0; |
cad | 4:6596cb2d1c90 | 38 | } |
cad | 4:6596cb2d1c90 | 39 | |
cad | 4:6596cb2d1c90 | 40 | lcd_txt.locate(0,1); |
cad | 4:6596cb2d1c90 | 41 | lcd_txt.printf("%d", count, count2); |
myren | 3:39825a5cf7cf | 42 | |
myren | 3:39825a5cf7cf | 43 | if (Btn1 == true)//scanner knap |
myren | 3:39825a5cf7cf | 44 | { |
cad | 4:6596cb2d1c90 | 45 | NewPress = true; |
myren | 3:39825a5cf7cf | 46 | lcd_txt.locate(0,3); |
myren | 3:39825a5cf7cf | 47 | lcd_txt.printf("Switch aktiv!"); |
myren | 3:39825a5cf7cf | 48 | } |
myren | 3:39825a5cf7cf | 49 | else |
myren | 3:39825a5cf7cf | 50 | { |
myren | 3:39825a5cf7cf | 51 | lcd_txt.locate(0,3); |
myren | 3:39825a5cf7cf | 52 | lcd_txt.printf(" "); |
cad | 4:6596cb2d1c90 | 53 | |
cad | 4:6596cb2d1c90 | 54 | if (NewPress == true) |
cad | 4:6596cb2d1c90 | 55 | { |
cad | 4:6596cb2d1c90 | 56 | |
cad | 4:6596cb2d1c90 | 57 | sprintf( tempString, "%d", count); |
cad | 4:6596cb2d1c90 | 58 | lcd_txt.locate(pos,2); |
cad | 4:6596cb2d1c90 | 59 | lcd_txt.printf(tempString); |
cad | 4:6596cb2d1c90 | 60 | |
cad | 4:6596cb2d1c90 | 61 | switch(pos) |
cad | 4:6596cb2d1c90 | 62 | { |
cad | 4:6596cb2d1c90 | 63 | case 0: |
cad | 4:6596cb2d1c90 | 64 | if (count == code[pos]) Led1 = true; |
cad | 4:6596cb2d1c90 | 65 | break; |
cad | 4:6596cb2d1c90 | 66 | case 1: |
cad | 4:6596cb2d1c90 | 67 | if (count == code[pos]) Led2 = true; |
cad | 4:6596cb2d1c90 | 68 | break; |
cad | 4:6596cb2d1c90 | 69 | case 2: |
cad | 4:6596cb2d1c90 | 70 | if (count == code[pos]) Led3 = true; |
cad | 4:6596cb2d1c90 | 71 | break; |
cad | 4:6596cb2d1c90 | 72 | case 3: |
cad | 4:6596cb2d1c90 | 73 | if (count == code[pos]) Led4 = true; |
cad | 4:6596cb2d1c90 | 74 | break; |
cad | 4:6596cb2d1c90 | 75 | case 4: |
cad | 4:6596cb2d1c90 | 76 | if (count == code[pos]) MyLed = true; |
cad | 4:6596cb2d1c90 | 77 | break; |
cad | 4:6596cb2d1c90 | 78 | |
cad | 4:6596cb2d1c90 | 79 | |
cad | 4:6596cb2d1c90 | 80 | } |
cad | 4:6596cb2d1c90 | 81 | |
cad | 4:6596cb2d1c90 | 82 | |
cad | 4:6596cb2d1c90 | 83 | |
cad | 4:6596cb2d1c90 | 84 | NewPress = false; |
cad | 4:6596cb2d1c90 | 85 | pos++; |
cad | 4:6596cb2d1c90 | 86 | } |
cad | 4:6596cb2d1c90 | 87 | } |
myren | 3:39825a5cf7cf | 88 | |
myren | 3:39825a5cf7cf | 89 | } |
myren | 3:39825a5cf7cf | 90 | |
myren | 3:39825a5cf7cf | 91 | } |
myren | 3:39825a5cf7cf | 92 | |
myren | 3:39825a5cf7cf | 93 | int main() |
myren | 3:39825a5cf7cf | 94 | { |
myren | 3:39825a5cf7cf | 95 | Thread thread(CheckBtn_thread); |
myren | 3:39825a5cf7cf | 96 | lcd_txt.cls(); |
cad | 4:6596cb2d1c90 | 97 | |
cad | 4:6596cb2d1c90 | 98 | lcd_txt.locate(0,0); |
cad | 4:6596cb2d1c90 | 99 | lcd_txt.printf("***** CLAUS *****"); |
cad | 4:6596cb2d1c90 | 100 | |
myren | 3:39825a5cf7cf | 101 | |
myren | 3:39825a5cf7cf | 102 | while (true) |
myren | 3:39825a5cf7cf | 103 | { |
cad | 4:6596cb2d1c90 | 104 | // Led1 = !Led1; //starter "tråd" i hovedprogram |
cad | 4:6596cb2d1c90 | 105 | Thread::wait(1000); |
myren | 3:39825a5cf7cf | 106 | } |
myren | 3:39825a5cf7cf | 107 | |
simon | 0:334327d1a416 | 108 | } |
myren | 3:39825a5cf7cf | 109 |