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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:fe11ae12c823
- Child:
- 1:98bd0c4131d8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 28 15:09:08 2022 +0000 @@ -0,0 +1,50 @@ +// TBRe-AI FRONT MBED +// MONITORS STEERING ANGLE AND WHEEL SPEED +// AND SENDS THEM OVER CAN BUS +// WRITTEN BY SEB HALL ON 29/06/2022 + +#include "mbed.h" + +const PinName writePin = p29; +const PinName readPin = p30; +const int busFrequency = 500000; +const unsigned int steeringMessageID = 100; + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +Serial pc(USBTX, USBRX); +AnalogIn steeringIn(p15); + +union { + double formattedData; + unsigned char rawData[8]; +} CANFormatted; + +CAN CANBus(readPin, writePin, busFrequency); + +void sendCANMessage(double data, unsigned int id) { + + CANMessage message; + + CANFormatted.formattedData = data; + + for (int i = 0; i < 8; i++) { + message.data[i] = CANFormatted.rawData[i]; + } + + message.id = id; + + CANBus.write(message); + +} + +int main() { + pc.printf("FRONT STARTED\n"); + led1 = !led1; + while(1) { + double num = (double) steeringIn.read(); + sendCANMessage(num, steeringMessageID); + led1 = !led1; + led2 = !led2; + } +} \ No newline at end of file