test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Revision:
0:d383e2dee0f7
Child:
3:96fcb3b041eb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 06 17:18:59 2020 +0530
@@ -0,0 +1,64 @@
+#include <global.h>
+
+Serial pc(USBTX, USBRX);
+Timer timer; 
+
+int main() {
+
+#if TEST_ULTRASONIC
+
+    JSN_SR04 sensor1(TIM1_CH2, TRIG_PA8_OUT);
+    JSN_SR04 sensor2(TIM1_CH2, TRIG_PA15_OUT);
+    JSN_SR04 sensor3(TIM1_CH2, TRIG_PA14_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
+
+}
+