
dfg
Dependencies: TextLCD mbed-rtos mbed
Fork of TextLCD_HelloWorld_SuperTue by
Diff: main.cpp
- Revision:
- 5:4eea67529466
- Parent:
- 4:6596cb2d1c90
--- a/main.cpp Fri Jan 23 19:33:12 2015 +0000 +++ b/main.cpp Tue Nov 22 13:59:02 2016 +0000 @@ -9,100 +9,79 @@ DigitalOut Led2 (LED2); DigitalOut Led3 (LED3); DigitalOut Led4 (LED4); -DigitalOut MyLed (p28); - +DigitalOut MyLed (p29); DigitalIn Btn1 (p27); -int count, count2,pos = 0; + + +int count, count2,AntalTryk = 0; bool NewPress = false; char tempString[1]; -int code[5] = { 2, 5, 4, 7, 5 }; + +void clearLed() +{ + Led1 = false; + Led2 = false; + Led3 = false; + Led4 = false; + +} void CheckBtn_thread(void const *args) { while (true) //tråd der scanner knapper { -// Led2 = !Led2; - Thread::wait(80); - count2++; - - if (count2 == 10) + if (Btn1 == true)//scanner knap Hvis der er trykket { - count2 = 0; - count++; - if (count == 10) - count = 0; - } - - lcd_txt.locate(0,1); - lcd_txt.printf("%d", count, count2); - - if (Btn1 == true)//scanner knap - { - NewPress = true; - lcd_txt.locate(0,3); - lcd_txt.printf("Switch aktiv!"); - } - else - { - lcd_txt.locate(0,3); - lcd_txt.printf(" "); + lcd_txt.locate(1,1); //Sætter position i displayet (kolone 0 række 3) + lcd_txt.printf("Knappen er trykket"); // Skriver en række med "Knap trykket" i displayet. - if (NewPress == true) - { - - sprintf( tempString, "%d", count); - lcd_txt.locate(pos,2); - lcd_txt.printf(tempString); + Thread::wait(100); // Venter 80 ms - switch(pos) - { - case 0: - if (count == code[pos]) Led1 = true; - break; - case 1: - if (count == code[pos]) Led2 = true; - break; - case 2: - if (count == code[pos]) Led3 = true; - break; - case 3: - if (count == code[pos]) Led4 = true; - break; - case 4: - if (count == code[pos]) MyLed = true; - break; + MyLed = !MyLed; // Tænder og slukker Led2 + } + else //Hvis knappen ikke er trykket + { + lcd_txt.locate(1,1); //Sætter position i displayet (kolone 0 række 3) + lcd_txt.printf(" "); // Skriver en række med "ingenting" i displayet. - - } - - - - NewPress = false; - pos++; - } } } } + int main() { Thread thread(CheckBtn_thread); - lcd_txt.cls(); + lcd_txt.cls(); //Sletter displayet - lcd_txt.locate(0,0); - lcd_txt.printf("***** CLAUS *****"); - + lcd_txt.locate(0,0); //Sætter position i displayet (kolone 0 række 0) + + lcd_txt.printf("Hej ....."); while (true) { - // Led1 = !Led1; //starter "tråd" i hovedprogram - Thread::wait(1000); + // Led1 = !Led1; // Blinket med Led 1. + Thread::wait(100); + + clearLed(); + switch(count) + { + case 0: + Led1 = true; + break; + case 1: //Ved første tryk tændes Led3 + Led2 = true; + count = -1; + break; + + } + count++; } }