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-18
- Revision:
- 4:f6e22dd39313
- Parent:
- 3:96fcb3b041eb
- Child:
- 5:97117a837d2c
File content as of revision 4:f6e22dd39313:
#include <global.h> Serial pc(UART1_TX, UART1_RX); Timer timer; int main() { // DigitalOut led(DEBUG_LED); DigitalOut led2(DE_TXD_1, 1); // activate transmitting rs485-1 // led = false; // while (true) { // led = !led; // wait_ms(BLINKING_RATE); // pc.printf("Distance:"); // } // #if TEST_ULTRASONIC int time_to_check_us = 1000; JSN_SR04 sensor1(TIM1_CH2, TRIG_PA8_OUT); // JSN_SR04 sensor1(TIM1_CH2, TRIG_PB14_OUT); //no triger signal // JSN_SR04 sensor1(TIM1_CH2, TRIG_PB15_OUT); sensor1.setRanges(30, 200); // sensor2.setRanges(30, 200); // sensor3.setRanges(30, 200); // pc.printf("Min. range = %g cm\n\r",sensor1.getMinRange()); while(true) { timer.reset(); timer.start(); sensor1.startMeasurement(); while (sensor1.isNewDataReady() == false && timer.read_ms() < time_to_check_us) { // pc.printf("c1"); // if (sensor1.isNewDataReady() == true) { // pc.printf("Distance1: %5.1f mm \r\n", sensor1.getDistance_cm()); // } } //timer.reset(); // timer.start(); //// pc.printf("\r\n"); // sensor2.startMeasurement(); // while (sensor2.isNewDataReady() == false && timer.read_ms() < time_to_check_us) { //// pc.printf("c2"); // } // timer.reset(); // timer.start(); // pc.printf("\r\n"); //sensor3.startMeasurement(); // while (sensor3.isNewDataReady() == false && timer.read_ms() < time_to_check_us) { // pc.printf("c3"); // } // // pc.printf("\r\n"); // pc.printf("Distance1: %5.1f mm -- Distance2: %5.1f mm -- -- Distance3: %5.1f mm \r\n", sensor1.getDistance_cm()), sensor2.getDistance_cm(), sensor3.getDistance_cm()); pc.printf("Distance1: %5.1f mm \r\n", sensor1.getDistance_cm()); timer.stop(); // wait_ms(150 - timer.read_ms()); // // timer.reset(); // timer.start(); // // sensor2.startMeasurement(); // pc.printf("Distance2: %5.1f mm \r\n", sensor2.getDistance_cm()); // // timer.stop(); // wait_ms(500 - timer.read_ms()); // // timer.reset(); // timer.start(); // // sensor3.startMeasurement(); // pc.printf("Distance3: %5.1f mm \r\n", sensor3.getDistance_cm()); // // timer.stop(); //wait_ms(500 - timer.read_ms()); // time the loop // // wait_ms(500 - timer.read_ms()); // time the loop } #endif #if TEST_ENCODERS int min1_value = 2000; int max1_value = 0; AS5045 encoder_1(SP1_NSS1); AS5045 encoder_2(SP1_NSS2); while(1) { led = !led; int encoder_1_Value = encoder_1.getPosition(); wait_ms(30); int encoder_2_Value = encoder_2.getPosition(); wait_ms(30); //encoder_1_Value = //if( encoder_1_Value.IsValid() && encoder_2_Value.IsValid() ) if(encoder_1_Value < min1_value) min1_value = encoder_1_Value; if(encoder_1_Value > max1_value) max1_value = encoder_1_Value; pc.printf("Sensor Values = %d --- %d \n\r",encoder_1_Value, encoder_2_Value ); // //else //pc.printf("Invalid data read"); //wait_ms(50); } #endif # if TEST_IR //E18_D80NK infared1 (IR1_PB12_OUT); // E18_D80NK infared2 (IR2_PB13_OUT); // while (true) { // pc.printf ("Is there any obstacle: %d ---- %d ", infared1.checkObstacle(),infared2.checkObstacle() ); // pc.printf ("\n\r"); // } #endif }