Руслан Бредун
/
stm32-sensor-base2
test
main.cpp
- Committer:
- nestedslk
- Date:
- 2020-07-21
- Revision:
- 5:97117a837d2c
- Parent:
- 4:f6e22dd39313
- Child:
- 6:a760ce6defbe
File content as of revision 5:97117a837d2c:
#include <global.h> Serial pc(UART1_TX, UART1_RX); //Serial pc(USBTX, USBRX); 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("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(10); } #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; double encoder_1_Value = encoder_1.getPosition(); wait_ms(30); double encoder_2_Value = encoder_2.getPosition(); wait_ms(30); //encoder_1_Value = //if( encoder_1_Value.IsValid() && encoder_2_Value.IsValid() ) pc.printf("Sensor Values = %f --- %f \n\r",encoder_1_Value, encoder_2_Value ); // //else //pc.printf("Invalid data read"); //wait_ms(50); } #endif # if TEST_IR PwmIn a(PB_4); //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 }