Ticker Example

Fork of Workshop-1-Example-2 by mbed Workshops

Committer:
thinkfire
Date:
Fri Jan 20 11:53:01 2017 +0000
Revision:
1:965926ce34a0
Parent:
0:41a092c2e9d3
tested

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sarahmarshy 0:41a092c2e9d3 1 #include "mbed.h"
sarahmarshy 0:41a092c2e9d3 2
thinkfire 1:965926ce34a0 3 Serial pc(USBTX,USBRX);
thinkfire 1:965926ce34a0 4
thinkfire 1:965926ce34a0 5 Ticker L1,L2,L3,L4;
thinkfire 1:965926ce34a0 6
sarahmarshy 0:41a092c2e9d3 7 DigitalOut led1(LED1);
sarahmarshy 0:41a092c2e9d3 8 DigitalOut led2(LED2);
thinkfire 1:965926ce34a0 9 DigitalOut led3(LED3);
thinkfire 1:965926ce34a0 10 DigitalOut led4(LED4);
sarahmarshy 0:41a092c2e9d3 11
thinkfire 1:965926ce34a0 12 void led_1() {
thinkfire 1:965926ce34a0 13 led1 = !led1;
thinkfire 1:965926ce34a0 14 //pc.printf("LED 1 toogled\n");
thinkfire 1:965926ce34a0 15 }
thinkfire 1:965926ce34a0 16
thinkfire 1:965926ce34a0 17 void led_2() {
sarahmarshy 0:41a092c2e9d3 18 led2 = !led2;
thinkfire 1:965926ce34a0 19 //pc.printf("LED 2 toogled\n");
thinkfire 1:965926ce34a0 20 }
thinkfire 1:965926ce34a0 21
thinkfire 1:965926ce34a0 22 void led_3() {
thinkfire 1:965926ce34a0 23 led3 = !led3;
thinkfire 1:965926ce34a0 24 // pc.printf("LED 3 toogled\n");
thinkfire 1:965926ce34a0 25 }
thinkfire 1:965926ce34a0 26
thinkfire 1:965926ce34a0 27 void led_4() {
thinkfire 1:965926ce34a0 28 led4 = !led4;
thinkfire 1:965926ce34a0 29 // pc.printf("LED 4 toogled\n");
sarahmarshy 0:41a092c2e9d3 30 }
sarahmarshy 0:41a092c2e9d3 31
sarahmarshy 0:41a092c2e9d3 32 int main() {
thinkfire 1:965926ce34a0 33 L1.attach(&led_1, ((rand()%10)+1));
thinkfire 1:965926ce34a0 34 L2.attach(&led_2, ((rand()%10)+1)); // call flip function every 2 seconds
thinkfire 1:965926ce34a0 35 L3.attach(&led_3, ((rand()%10)+1));
thinkfire 1:965926ce34a0 36 L4.attach(&led_4, ((rand()%10)+1));
sarahmarshy 0:41a092c2e9d3 37
sarahmarshy 0:41a092c2e9d3 38 // spin in a main loop. flipper will interrupt it to call flip
sarahmarshy 0:41a092c2e9d3 39 while(1) {
thinkfire 1:965926ce34a0 40
thinkfire 1:965926ce34a0 41 }
sarahmarshy 0:41a092c2e9d3 42 }