Random terror phrases
Dependencies: EFM32_CapSenseSlider EFM32_SegmentLCD mbed
Fork of EMF32-Segment-Touch-Demo by
Revision 2:9c22b1264236, committed 2015-09-29
- Comitter:
- MaxScorda
- Date:
- Tue Sep 29 14:04:48 2015 +0000
- Parent:
- 1:611525c0aa76
- Commit message:
- 1.0
Changed in this revision
Functions.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 611525c0aa76 -r 9c22b1264236 Functions.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Functions.h Tue Sep 29 14:04:48 2015 +0000 @@ -0,0 +1,179 @@ +#include <string> + + +char* string2char(string sttde) +{ + //ora aggiunge comunque l'EOS. Decidere se parametrizzare + //sttde=addEOS(sttde); + char *cstr = new char[sttde.length() + 1]; + strcpy(cstr, sttde.c_str()); + // delete [] cstr; + return cstr; +} + +//****************** FUNZIONI STANDARD NON MODIFICATE +/** + * Callback for pushbutton interrupt + */ + +void symbolGest() +{ + if (count==7) { + segmentDisplay.Symbol(LCD_SYMBOL_GECKO, true); + segmentDisplay.Write("GeckoOn"); + pc.printf("Gecko! \n\r"); + } else { + segmentDisplay.Symbol(LCD_SYMBOL_GECKO, false); + if (count%2==0) segmentDisplay.Write("Scorda"); + else segmentDisplay.Write("TataGek"); + } +} + + +void ledToggler(void) +{ + myled1 = !myled1; +} + +void ledTogglerGen(void) +{ + myled0 = !myled0; + segmentDisplay.Symbol(LCD_SYMBOL_GECKO, false); + myled1=1; + ledTicker1.detach(); +} + + +void timeDisp() +{ + seconds++; + uint32_t clockValue = ((seconds / 60) % 60) * 100 + (seconds % 60); + segmentDisplay.Number(clockValue); + segmentDisplay.Symbol(LCD_SYMBOL_COL10, seconds & 0x1); + +} + +/** + * Callback for display + */ +void tickerCallback(void) +{ + float rtime; + int choicev; + string mess; + + //choice + choicev=rand()%15; + + switch (choicev) { + case 0: + mess="Vai Via"; + break; + case 1: + mess="Via!!"; + break; + case 2: + mess="Vattene"; + break; + case 3: + mess="Aiuto!"; + break; + case 4: + mess="Basta!"; + break; + case 5: + mess="Paura!"; + break; + case 6: + mess="No!"; + break; + case 7: + mess="No!No!!"; + break; + case 8: + mess="Noooooo"; + break; + case 9: + mess="Lontano"; + break; + case 10: + mess="Aaargh"; + break; + case 11: + mess="Aaahhh"; + break; + case 12: + mess="Orrore!"; + break; + case 13: + mess="Vattene"; + break; + case 14: + mess="Oddioo"; + break; + } +//display + segmentDisplay.Write(string2char(mess)); + //ricalcolo ticker + rtime=((rand()%4000)+1000)/1000; + refreshTicker.detach(); + refreshTicker.attach(&tickerCallback, rtime); + myled0 = 1; + segmentDisplay.Symbol(LCD_SYMBOL_GECKO, true); + ledTicker0.detach(); + ledTicker0.attach(&ledTogglerGen, rtime/2); + ledTicker1.attach(&ledToggler, 0.1f); +} + +/** + * Callback for touching/untouching the cap slider + */ + + +void touchCallback(void) +{ + segmentDisplay.Symbol(LCD_SYMBOL_EFM32, capSlider.isTouched()); + + if(!capSlider.isTouched()) { + segmentDisplay.Write("Bestia!"); + printf("Touch in use \n\r"); + } +} + +/** + * Callback for sliding the cap slider + */ +void slideCallback(void) +{ + segmentDisplay.LowerNumber(capSlider.get_position()); +} + +//************************ FUNZIONI MODIFICATE +void in0_handler() +{ + segmentDisplay.Write("No 0!"); + /* + pc.printf("Button 0 \n\r"); + count++; + if (count>7) count=7; + else segmentDisplay.ARing(count, true); + symbolGest() ; + */ +} + +void in1_handler() +{ + segmentDisplay.Write("No 1!"); + /* + printf("Button 1 \n\r"); + segmentDisplay.ARing(count, false); + count--; + if (count<0) count=-1; + symbolGest() ; + */ +} + + + + +
diff -r 611525c0aa76 -r 9c22b1264236 main.cpp --- a/main.cpp Fri Jun 26 11:36:58 2015 +0000 +++ b/main.cpp Tue Sep 29 14:04:48 2015 +0000 @@ -1,3 +1,13 @@ +/** ************************************** +In un tempo variabile tra 1 e 5 secondi, refreshticker cambia scritta e nel contempo cambia: +- temporizzazione di led0: meta' tempo acceso l'altra meta' spento +- temporizzazione di led1: meta' tempo lampeggia, l'altra meta' (controllata dal'evento led0) resta acceso +- accende io jecko che viene spento da led0 +I tasti rispondono, il sensore pure + + +*/ + #include "EFM32_SegmentLCD.h" #include "EFM32_CapSenseSlider.h" @@ -11,14 +21,17 @@ DigitalOut myled1(LED1); DigitalOut myled0(LED0); +Serial pc(USBTX, USBRX); //Apertura della seriale 2 + /******************** Define Timers *****************************/ // devo separare i timers. Non so il perche' LowPowerTicker refreshTicker; LowPowerTicker ledTicker0; LowPowerTicker ledTicker1; +LowPowerTicker timeTicker; /***************** Define global variables **********************/ -#define INIT_SECONDS 17600 +#define INIT_SECONDS 0 #define TEST_DURATION 10 volatile uint32_t seconds = INIT_SECONDS; @@ -32,82 +45,10 @@ void touchCallback(void); void slideCallback(void); -/** - * Callback for pushbutton interrupt - */ - -void symbolGest() -{ - if (count==7) { - segmentDisplay.Symbol(LCD_SYMBOL_GECKO, true); - segmentDisplay.Write("GeckoOn"); - } else { - segmentDisplay.Symbol(LCD_SYMBOL_GECKO, false); - if (count%2==0) segmentDisplay.Write("Scorda"); - else segmentDisplay.Write("TataGek"); - } - -} - -void in0_handler() -{ - count++; - if (count>7) count=7; - else segmentDisplay.ARing(count, true); - symbolGest() ; - -} - -void in1_handler() -{ - segmentDisplay.ARing(count, false); - count--; - if (count<0) count=-1; - symbolGest() ; - -} - +//------------ Funzioni ------------- -/** - * Callback for 1 second timebase - */ -void tickerCallback(void) -{ - seconds++; - uint32_t clockValue = ((seconds / 60) % 60) * 100 + (seconds % 60); - segmentDisplay.Number(clockValue); - segmentDisplay.Symbol(LCD_SYMBOL_COL10, seconds & 0x1); -} - -/** - * Callback for touching/untouching the cap slider - */ -void touchCallback(void) -{ - segmentDisplay.Symbol(LCD_SYMBOL_EFM32, capSlider.isTouched()); +#include "Functions.h" - if(!capSlider.isTouched()) { - segmentDisplay.Write("Scorda"); - } -} - -/** - * Callback for sliding the cap slider - */ -void slideCallback(void) -{ - segmentDisplay.LowerNumber(capSlider.get_position()); -} - -void ledToggler(void) -{ - myled1 = !myled1; -} - -void ledTogglerGen(void) -{ - myled0 = !myled0; -} /*************************** MAIN *******************************/ int main() @@ -127,29 +68,19 @@ // Start generating the 1Hz timebase refreshTicker.attach(&tickerCallback, 1.0f); - ledTicker1.attach(&ledToggler, 0.4f); + timeTicker.attach(&timeDisp, 1.0f); ledTicker0.attach(&ledTogglerGen, 0.5f); + ledTicker1.attach(&ledToggler, 0.1f); - printf("Initialization done! \n"); + printf("Initialization done! \n\r"); wait(0.01f); //Need to delay slightly to give the serial transmission a chance to flush out its buffer - segmentDisplay.Write("Scorda"); + //inizializza random + srand (time(NULL)); // Go into sleeping mode while(1) { sleep(); - - if(count >= 8) { - /* - // Go to 'completely dead' mode to show power consumption - refreshTicker.detach(); - capSlider.stop(); - in.disable_irq(); - delete &segmentDisplay; - - */ - } - } }