TRACE.ino 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Description: Read the status of the four line-tracking sensors of TRACE Unit and output them through UART.
  3. */
  4. #include <M5Stack.h>
  5. // #define VALUE_SPLIT
  6. uint8_t value;
  7. int SensorArray[4] = {0};
  8. void setup() {
  9. m5.begin();
  10. M5.Power.begin();
  11. Serial.begin(115200);
  12. Wire.begin();
  13. M5.Lcd.clear(BLACK);
  14. M5.Lcd.setTextColor(YELLOW);
  15. M5.Lcd.setTextSize(2);
  16. M5.Lcd.setCursor(80, 0);
  17. M5.Lcd.println("TRACE example");
  18. M5.Lcd.setTextColor(WHITE);
  19. }
  20. void loop(){
  21. SensorStatus();
  22. delay(100);
  23. }
  24. void SensorStatus(void){
  25. Wire.beginTransmission(0x5a);
  26. Wire.write(0x00);
  27. Wire.endTransmission();
  28. Wire.requestFrom(0x5a,1);
  29. while(Wire.available()){
  30. value = Wire.read();
  31. }
  32. Serial.print(" value = ");Serial.println(value, HEX);
  33. #ifdef VALUE_SPLIT
  34. SensorArray[3] = (value&0x08)>>3;
  35. SensorArray[2] = (value&0x04)>>2;
  36. SensorArray[1] = (value&0x02)>>1;
  37. SensorArray[0] = (value&0x01)>>0;
  38. Serial.println("After splitting... ");
  39. Serial.print("SensorArray[0] = ");Serial.print(SensorArray[0]);
  40. Serial.print(" SensorArray[1] = ");Serial.print(SensorArray[1]);
  41. Serial.print(" SensorArray[2] = ");Serial.print(SensorArray[2]);
  42. Serial.print(" SensorArray[3] = ");Serial.print(SensorArray[3]);
  43. Serial.println();
  44. #endif
  45. }