GoPLUS.ino 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Description: Use GoPLUS Module for four-channel servo test and three-channel ADC test.
  3. */
  4. #include <M5Stack.h>
  5. #include <Wire.h>
  6. #include "GoPlus.h"
  7. GoPlus goPlus;
  8. #define X_LOCAL 40
  9. #define Y_LOCAL 30
  10. #define X_OFFSET 160
  11. #define Y_OFFSET 23
  12. // Print the header for a display screen
  13. void header(const char *string, uint16_t color)
  14. {
  15. M5.Lcd.fillScreen(color);
  16. M5.Lcd.setTextSize(1);
  17. M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLUE);
  18. M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLUE);
  19. M5.Lcd.setTextDatum(TC_DATUM);
  20. M5.Lcd.drawString(string, 160, 3, 4);
  21. }
  22. void Motor(void){
  23. goPlus.Motor_write_speed(MOTOR_NUM0, (uint8_t)0x80, 250);
  24. goPlus.Motor_write_speed(MOTOR_NUM1, (uint8_t)0x80, 250);
  25. delay(500);
  26. goPlus.Motor_write_speed(MOTOR_NUM0, (uint8_t)0x80, 0);
  27. goPlus.Motor_write_speed(MOTOR_NUM1, (uint8_t)0x00, 0);
  28. delay(500);
  29. goPlus.Motor_write_speed(MOTOR_NUM1, (uint8_t)0x00, 250);
  30. goPlus.Motor_write_speed(MOTOR_NUM0, (uint8_t)0x00, 250);
  31. delay(500);
  32. goPlus.Motor_write_speed(MOTOR_NUM0, (uint8_t)0x80, 0);
  33. goPlus.Motor_write_speed(MOTOR_NUM1, (uint8_t)0x00, 0);
  34. delay(500);
  35. }
  36. void setup() {
  37. // put your setup code here, to run once:
  38. M5.begin();
  39. M5.Power.begin();
  40. goPlus.begin();
  41. header("G O P L U S",TFT_BLACK);
  42. M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLACK);
  43. M5.Lcd.setCursor(X_LOCAL, Y_LOCAL, 2);
  44. M5.Lcd.printf("Read analog\n");
  45. M5.Lcd.setCursor(X_LOCAL+X_OFFSET, Y_LOCAL, 2);
  46. M5.Lcd.printf("Test Servo\n");
  47. M5.Lcd.setCursor(X_OFFSET-60, Y_LOCAL+Y_OFFSET*5, 2);
  48. M5.Lcd.printf("Test MoTor\n");
  49. M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
  50. pinMode(13,OUTPUT);
  51. }
  52. uint8_t a = 20;
  53. uint16_t adInValue[6] = {0};
  54. int led = 0;
  55. void loop() {
  56. // put your main code here, to run repeatedly:
  57. digitalWrite(13, led);
  58. goPlus.Servo_write_angle(SERVO_NUM0, a); delay(100);
  59. goPlus.Servo_write_angle(SERVO_NUM1 , a); delay(100);
  60. goPlus.Servo_write_angle(SERVO_NUM2 , a); delay(100);
  61. goPlus.Servo_write_angle(SERVO_NUM3 , a); delay(100);
  62. if (a > 180) {
  63. a = 10;
  64. }
  65. a = a + 170;
  66. M5.Lcd.fillRect(X_LOCAL+X_OFFSET, Y_LOCAL+Y_OFFSET, 100, 23, TFT_BLACK);
  67. M5.Lcd.setCursor(X_LOCAL+X_OFFSET, Y_LOCAL+Y_OFFSET, 2);
  68. M5.Lcd.printf("Angle:%d",a);
  69. adInValue[0] = goPlus.hub1_d_read_value(HUB_NUM0);
  70. delay(50);
  71. M5.Lcd.fillRect(X_LOCAL, Y_LOCAL+Y_OFFSET*1, 100, 23, TFT_BLACK);
  72. M5.Lcd.setCursor(X_LOCAL, Y_LOCAL+Y_OFFSET*1, 2);
  73. M5.Lcd.printf("A0:%d",adInValue[0]);
  74. adInValue[1] = goPlus.hub2_d_read_value(HUB_NUM0);
  75. delay(50);
  76. M5.Lcd.fillRect(X_LOCAL, Y_LOCAL+Y_OFFSET*2, 100, 23, TFT_BLACK);
  77. M5.Lcd.setCursor(X_LOCAL, Y_LOCAL+Y_OFFSET*2, 2);
  78. M5.Lcd.printf("A1:%d",adInValue[1]);
  79. adInValue[2] = goPlus.hub3_d_read_value(HUB_NUM0);
  80. delay(50);
  81. M5.Lcd.fillRect(X_LOCAL, Y_LOCAL+Y_OFFSET*3, 100, 23, TFT_BLACK);
  82. M5.Lcd.setCursor(X_LOCAL, Y_LOCAL+Y_OFFSET*3, 2);
  83. M5.Lcd.printf("A2:%d",adInValue[2]);
  84. led = !led;
  85. Motor();
  86. }