Michael Antonucci / Mbed 2 deprecated A3_2_Ticker

Dependencies:   mbed

Committer:
slicht_instructor
Date:
Tue Oct 11 13:38:14 2022 +0000
Revision:
2:302216e564bf
Parent:
1:76d11e984b8d
2022 Update;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
slicht_instructor 1:76d11e984b8d 1 //Base code for modification for Assignment 3.2
slicht_instructor 1:76d11e984b8d 2 //Blinks LED2 every 200ms using a single Ticker object.
slicht_instructor 0:5597320f2dba 3 //Created: S. Licht, 10/04/2020
slicht_instructor 1:76d11e984b8d 4 #include "mbed.h"
slicht_instructor 1:76d11e984b8d 5 Ticker tickerLED2; //creat ticker object
slicht_instructor 2:302216e564bf 6 InterruptIn switch1(p5);
slicht_instructor 1:76d11e984b8d 7 DigitalOut LEDOut2(LED2);
slicht_instructor 2:302216e564bf 8 DigitalOut LEDOut4(LED4);
slicht_instructor 0:5597320f2dba 9
slicht_instructor 1:76d11e984b8d 10 void changeLED2() //the function that will be called by the ticker object.
slicht_instructor 1:76d11e984b8d 11 {
slicht_instructor 1:76d11e984b8d 12 LEDOut2 = !LEDOut2;
slicht_instructor 1:76d11e984b8d 13 }
slicht_instructor 0:5597320f2dba 14
slicht_instructor 2:302216e564bf 15 void changeLED4() //the function that will be called by the ticker object.
slicht_instructor 2:302216e564bf 16 {
slicht_instructor 2:302216e564bf 17 LEDOut4 = !LEDOut4;
slicht_instructor 2:302216e564bf 18 }
slicht_instructor 2:302216e564bf 19
slicht_instructor 2:302216e564bf 20
slicht_instructor 0:5597320f2dba 21 int main()
slicht_instructor 0:5597320f2dba 22 {
slicht_instructor 2:302216e564bf 23 tickerLED2.attach(&changeLED2,0.5); //the address of the function to call
slicht_instructor 1:76d11e984b8d 24 //and the interval in seconds between
slicht_instructor 1:76d11e984b8d 25 //calls to that function
slicht_instructor 0:5597320f2dba 26
slicht_instructor 0:5597320f2dba 27 while(1) {
slicht_instructor 1:76d11e984b8d 28 wait(0.1);
slicht_instructor 1:76d11e984b8d 29 wait(0.1);
slicht_instructor 1:76d11e984b8d 30 wait(0.1);
slicht_instructor 2:302216e564bf 31 //the main loop is spinning every 300ms, but the LED needs to go faster!
slicht_instructor 2:302216e564bf 32
slicht_instructor 0:5597320f2dba 33 } //while
slicht_instructor 2:302216e564bf 34
slicht_instructor 2:302216e564bf 35 switch1.rise(&changeLED4);
slicht_instructor 2:302216e564bf 36
slicht_instructor 0:5597320f2dba 37 }