Tryout the TOF sensor Only

Dependencies:   VL53L0X_Condensed

Files at this revision

API Documentation at this revision

Comitter:
sepp_nepp
Date:
Mon Mar 25 20:47:33 2019 +0000
Parent:
15:e0fbd2ddd2a9
Commit message:
That compiles now

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e0fbd2ddd2a9 -r 6a5a62b00ed1 main.cpp
--- a/main.cpp	Sun Mar 24 22:25:09 2019 +0000
+++ b/main.cpp	Mon Mar 25 20:47:33 2019 +0000
@@ -64,7 +64,7 @@
 
 /* Simple main function */
 int main() {
-  uint32_t distance;
+  uint32_t distance, NewDist, OldDist;
   int status;
   char NoteNr, Octave, ScaleNote;
   char OldKey, NewKey;
@@ -73,19 +73,20 @@
   /* Init all sensors with default params */
   tof1.init_sensor(VL53L0X_DEFAULT_ADDRESS);
   status = tof1.start_measurement(range_continuous_polling, NULL);
+  status = status | tof1.VL53L0X_set_measurement_timing_budget_us(100000);
   if (status) 
      {  printf("\n\r--- Error Initializing the TOF sensor ---\n\r"); 
         //while(1) { }; // consider to hang up the device here
      }
   printf("\n\r--- Read Init of TOF ---\n\r"); ;
          
-  OldKey = 0x00; // Remembers the old key, start with value thats normallz unused 
+  OldKey = 0x00; // Remembers the old key, start with value thats normally unused 
   midi_uart.baud( 31250 );
   midi_uart.format( 8, SerialBase::None, 2);
   wait(0.1); // make sure all is settled
-  midi_uart.putc(0xB0);   // Midi Channel 0, Channel Mode Message
-  midi_uart.putc(123);    // Byte 2: All Notes Off
-  midi_uart.putc(0x00);   // Byte 3: obligatory zero 
+  midi_uart.putc(0xB0);  // Midi Channel 0, Channel Mode Message
+  midi_uart.putc(123);   // Byte 2: All Notes Off
+  midi_uart.putc(0x00);  // Byte 3: obligatory zero 
   
  
   while(1)
@@ -93,14 +94,15 @@
         
     if ( (status == VL53L0X_ERROR_NONE) && (p_ranging_measurement_data.RangeStatus == 0) )
         { // we have a valid range.
-        distance = p_ranging_measurement_data.RangeMilliMeter;
+        NewDist = p_ranging_measurement_data.RangeMilliMeter;
         // printf("%6ld\r", distance); // Distance is ~1700 when looking at the ceiling, so approximately 1 per mm. A really usable distance range is only up to 1270. 
-        distance = (int) (distance / 10) + 20; // scaling factor 10 between distance and key note
+        distance = (int) ( NewDist / 30 + OldDist / 20 ) + 20; // scaling factor 10 between distance and key note
         if (distance >= 0x7F) NoteNr = 0x00; // cap the New Key Value on the top, beyond 127 we discard the note as 'no Note'
             else NoteNr = distance; // pass through everything below; remember: distance is uint, so no negatives can occur
         Octave = (int) (NoteNr / 7);
         ScaleNote = NoteNr - (Octave * 7);
-        NewKey = Octave * 12 + MiShebera[ScaleNote];
+        NewKey = Octave * 12 + TsigaMoll[ScaleNote];
+        OldDist = NewDist;
         } 
       else 
         { // printf("  --\r");