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: LineFollowingRobot/main.cpp
- Revision:
- 1:a2ceed49374e
- Parent:
- 0:a02a278513d9
- Child:
- 2:74d8b693bc62
--- a/LineFollowingRobot/main.cpp Sat Jan 26 18:18:13 2019 +0000 +++ b/LineFollowingRobot/main.cpp Sat Feb 02 16:11:37 2019 +0000 @@ -1,38 +1,19 @@ #include <mbed.h> #include "RobotControl_H.h" - -DigitalIn leftIR(PTC6); -DigitalIn midLeftIR(PTC5); -DigitalIn midIR(PTC4); -DigitalIn midRightIR(PTC3); -DigitalIn rightIR(PTC0); - -Ticker sampling; -bool lineSensor[5], toggle2 = false; +#include "IRSensor_H.h" -void Sample(){ - //function attached to the ticker - //assigns the data recieved for each digital in into an array - //toggle is toggled at every ISR, signifying the ISR has occured - - lineSensor[0] = leftIR; - lineSensor[1] = midLeftIR; - lineSensor[2] = midIR; - lineSensor[3] = midRightIR; - lineSensor[4] = rightIR; - - toggle2 = !toggle2; -} - +Ticker sampling; int main(){ -//get a first reading -Sample(); -sampling.attach(&Sample, 0.01); +bool toggleIR; + +IRSensor IRSensor(PTC6, PTC5, PTC4, PTC3, PTC0, 0.0, 0.0, 0.0); + +sampling.attach(callback(&IRSensor, &IRSensor::Sample), 0.01); RobotControl controlLeft(PTC12,PTD4,PTA5); RobotControl controlRight(PTA13,PTA12,PTA4); @@ -40,7 +21,14 @@ while(1){ - wait(1); + + + if(toggleIR != IRSensor.m_toggle){ + IRSensor.WeightPID(); + IRSensor.CalculatePID(); + IRSensor.MotorControl(controlLeft,controlRight); + } + } } \ No newline at end of file