Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:c3344ac96db1
- Child:
- 1:e4320a230347
diff -r 000000000000 -r c3344ac96db1 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 14 12:53:00 2019 +0000 @@ -0,0 +1,49 @@ +#include "mbed.h" +#include "ColourSensor_H.h" + +Ticker detectColour; +Timeout readColour; +Timeout reactivateColour; + +int main() { + printf("Program has started\n\r"); + + ColourSensor ColourSensor(PTC16, PTC13, PTC12); + + // Set call rate of colour detection function + detectColour.attach(callback(&ColourSensor, &ColourSensor::readIf), 1.0); + + // Test LED + //testLED2.period(1.0); + //testLED2.write(0.5); + + int firstLoop = 1; + + while (1) { + // main program loop + if (firstLoop) { + printf("Main loop has started\n\r"); + firstLoop--; + } + + if (ColourSensor.toggleConst && ColourSensor.toggleA) { + // Call readColSenWhich after x seconds + printf("Toggle A\n\r"); + + readColour.attach(callback(&ColourSensor, &ColourSensor::readWhich), 0.4); + + ColourSensor.toggleA = 0; + } + + if (ColourSensor.toggleConst && ColourSensor.toggleB) { + // Process colour sensor data + printf("Toggle B\n\r"); + + ColourSensor.process(); + + reactivateColour.attach(callback(&ColourSensor, &ColourSensor::makeColourActive), 2.0); + + ColourSensor.toggleB = 0; + } + } +}