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:
- ommpy
- Date:
- 2020-07-23
- Revision:
- 7:2f218add711e
- Parent:
- 6:a760ce6defbe
- Child:
- 8:c3cffab85b0d
File content as of revision 7:2f218add711e:
#include <global.h> //Serial pc(UART1_TX, UART1_RX); RS485 RS485(UART2_TX,UART2_RX,DE_TXD_2); // Tx, Rx , !RE and DE MAX485 pin Serial pc(USBTX, USBRX); Timer timer; typedef uint8_t byte; DigitalOut select(DE_TXD_2); byte full_value[9]; byte base_data[4] = {0xAA,0x55,0x03,0x01}; byte data[9] = {0x01,0x04,0x00,0x48,0x00,0x02,0xf1,0xdd};//your data char test_buffer[10]; const unsigned char CRC7_POLY = 0x91; unsigned char getCRC(unsigned char message[], unsigned char length) { unsigned char i, j, crc = 0; for (i = 0; i < length; i++) { crc ^= message[i]; for (j = 0; j < 8; j++) { if (crc & 1) crc ^= CRC7_POLY; crc >>= 1; } } return crc; } int main() { DigitalOut led(DEBUG_LED); DigitalOut led2(DE_TXD_1, 1); // activate transmitting rs485-1 #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(2); } #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 # if DEMO_CODE JSN_SR04 sensor1(TIM1_CH2, TRIG_PA8_OUT); E18_D80NK infared1 (IR1_PB12_OUT); E18_D80NK infared2 (IR2_PB13_OUT); pc.baud(115200); sensor1.setRanges(10, 200); 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("%5.1f_%d_%d \r\n", sensor1.getDistance_cm(),infared1.checkObstacle(),infared2.checkObstacle()); timer.stop(); wait_ms(20); } #endif }