Testing STM Gateway/Node

Dependencies:   mbed

Committer:
benpen10
Date:
Tue Jun 19 16:51:31 2018 +0000
Revision:
0:0c324a364c5b
draft1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
benpen10 0:0c324a364c5b 1 #include "mbed.h"
benpen10 0:0c324a364c5b 2
benpen10 0:0c324a364c5b 3 DigitalOut myled1(LED1);
benpen10 0:0c324a364c5b 4 DigitalOut myled2(LED2);
benpen10 0:0c324a364c5b 5 DigitalOut myled3(LED3);
benpen10 0:0c324a364c5b 6 DigitalOut myled4(LED4);
benpen10 0:0c324a364c5b 7
benpen10 0:0c324a364c5b 8 InterruptIn mybutton(USER_BUTTON);
benpen10 0:0c324a364c5b 9
benpen10 0:0c324a364c5b 10 double tempo = 0.3; // LED blinking delay
benpen10 0:0c324a364c5b 11
benpen10 0:0c324a364c5b 12 // Change LEDs blinking frequency
benpen10 0:0c324a364c5b 13 void change_blinking_frequency() {
benpen10 0:0c324a364c5b 14 if (tempo == 0.3) // If leds have low frequency
benpen10 0:0c324a364c5b 15 tempo = 0.1; // Set the fast frequency
benpen10 0:0c324a364c5b 16 else // If leds have fast frequency
benpen10 0:0c324a364c5b 17 tempo = 0.3; // Set the low frequency
benpen10 0:0c324a364c5b 18 }
benpen10 0:0c324a364c5b 19
benpen10 0:0c324a364c5b 20 int main() {
benpen10 0:0c324a364c5b 21 // All LEDs are OFF
benpen10 0:0c324a364c5b 22 myled1 = 0;
benpen10 0:0c324a364c5b 23 myled2 = 0;
benpen10 0:0c324a364c5b 24 myled3 = 0;
benpen10 0:0c324a364c5b 25 myled4 = 0;
benpen10 0:0c324a364c5b 26
benpen10 0:0c324a364c5b 27 // Change LEDs blinking frequency when button is pressed
benpen10 0:0c324a364c5b 28 mybutton.fall(&change_blinking_frequency);
benpen10 0:0c324a364c5b 29
benpen10 0:0c324a364c5b 30 while(1) {
benpen10 0:0c324a364c5b 31 myled2 = 1; // LED2 is ON
benpen10 0:0c324a364c5b 32 wait(tempo); // wait tempo
benpen10 0:0c324a364c5b 33 myled2 = 0; // LED2 is OFF
benpen10 0:0c324a364c5b 34 myled1 = 1; // LED1 is ON
benpen10 0:0c324a364c5b 35 wait(tempo); // wait tempo
benpen10 0:0c324a364c5b 36 myled1 = 0; // LED1 is OFF
benpen10 0:0c324a364c5b 37 myled3 = 1; // LED3 is ON
benpen10 0:0c324a364c5b 38 wait(tempo); // wait tempo
benpen10 0:0c324a364c5b 39 myled3 = 0; // LED3 is OFF
benpen10 0:0c324a364c5b 40 myled4 = 1; // LED4 is ON
benpen10 0:0c324a364c5b 41 wait(tempo); // wait tempo
benpen10 0:0c324a364c5b 42 myled4 = 0; // LED4 is OFF
benpen10 0:0c324a364c5b 43 }
benpen10 0:0c324a364c5b 44 }