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 Watchdog stm32-sensor-base2
main.cpp
- Committer:
- nestedslk
- Date:
- 2020-07-07
- Revision:
- 3:96fcb3b041eb
- Parent:
- 0:d383e2dee0f7
- Child:
- 4:f6e22dd39313
File content as of revision 3:96fcb3b041eb:
#include <global.h>
Serial pc(UART1_TX, UART1_RX);
Timer timer;
int main() {
#if TEST_ULTRASONIC
JSN_SR04 sensor1(TIM1_CH2, TRIG_PA8_OUT);
JSN_SR04 sensor2(TIM1_CH2, TRIG_PB15_OUT);
JSN_SR04 sensor3(TIM1_CH2, TRIG_PB14_OUT);
sensor1.setRanges(10, 110);
sensor2.setRanges(10, 110);
sensor3.setRanges(10, 110);
pc.printf("Min. range = %g cm\n\rMax. range = %g cm\n\r",sensor1.getMinRange(), sensor1.getMaxRange());
while(true) {
timer.reset();
timer.start();
sensor1.startMeasurement();
sensor2.startMeasurement();
sensor3.startMeasurement();
while(!sensor1.isNewDataReady() || !sensor2.isNewDataReady() || !sensor3.isNewDataReady()) {
// wait for new data
// waiting time depends on the distance
}
pc.printf("Distance: %5.1f mm %5.1f mm %5.1f mm \r\n", sensor1.getDistance_mm(),sensor2.getDistance_mm(),sensor3.getDistance_mm());
timer.stop();
wait_ms(50 - timer.read_ms()); // time the loop
}
#endif
#if TEST_ENCODERS
AS5045Controller encoder_1(SP1_NSS1);
AS5045Controller encoder_2(SP1_NSS2);
while(1)
{
int encoder_1_Value = encoder_1.Read();
int encoder_2_Value = encoder_2.Read();
if( encoder_1_Value.IsValid() && encoder_2_Value.IsValid() )
pc.printf("Sensor Values = %d\n\r",encoder_1_Value ,encoder_2_Value );
else
pc.printf("Invalid data read");
Thread::wait(2);
}
#endif
# if TEST_IR
E18_D80NK infared (<your pin>);
while (true) {
pc.printf ("Is there any obstacle:", infared.checkObstacle ());
}
#endif
}