cute_useless_robot.ino 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Cute Useless Robot (´・ω・`)
  3. Developed by tobychui
  4. Original design by Kairoshi
  5. */
  6. /* Libraries */
  7. #include <MD_MAX72xx.h>
  8. #include <SPI.h>
  9. #include <Servo.h> //Require ESP32Servo, not the Arduino build in Servo.h
  10. /* Pins Definations */
  11. #define STP_DATA_PIN 4 // Stepper Shift Register DS
  12. #define STP_CLOCK_PIN 16 // Stepper Shift Register SH_CP
  13. #define STP_LATCH_PIN 17 // Stepper Shift Register ST_CP
  14. #define SERVO_SWITCH 27 //Servo to push the switch
  15. #define SERVO_COVER 14 //Servo to push the cover
  16. #define DP_CLK_PIN 32 //Display CLK
  17. #define DP_DATA_PIN 33 //Display DIN
  18. #define DP_CS_PIN 25 //Display CS
  19. /* Display settings generated by trial and error. Don't touch these */
  20. #define HARDWARE_TYPE MD_MAX72XX::DR1CR0RR0_HW
  21. #define MAX_DEVICES 8
  22. /* Hardware Type Definations */
  23. Servo servoSwitchPusher;
  24. Servo servoCoverPusher;
  25. MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DP_DATA_PIN, DP_CLK_PIN, DP_CS_PIN, MAX_DEVICES);
  26. void setup() {
  27. Serial.begin(115200);
  28. /* Stepper IO */
  29. pinMode(STP_DATA_PIN, OUTPUT);
  30. pinMode(STP_CLOCK_PIN, OUTPUT);
  31. pinMode(STP_LATCH_PIN, OUTPUT);
  32. /* Servo IO */
  33. servoSwitchPusher.attach(SERVO_SWITCH);
  34. servoCoverPusher.attach(SERVO_COVER);
  35. /* Display Module */
  36. mx.begin();
  37. setDisplayBrightness(0x4);
  38. renderFrame();
  39. delay(5000);
  40. }
  41. void loop() {
  42. //Stepper test
  43. forward(50);
  44. delay(3000);
  45. backward(50);
  46. delay(3000);
  47. rotateAntiClockwise(100);
  48. delay(3000);
  49. rotateClockwise(100);
  50. delay(3000);
  51. //Servo test
  52. servoCoverPusher.write(90);
  53. delay(1000);
  54. servoSwitchPusher.write(180);
  55. delay(1000);
  56. servoCoverPusher.write(0);
  57. servoSwitchPusher.write(0);
  58. delay(3000);
  59. }