cute_useless_robot.ino 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Cute Useless Robot (´・ω・`)
  3. Developed by tobychui
  4. Idea come from Kairoshi
  5. */
  6. /* Libraries */
  7. #include <MD_MAX72xx.h>
  8. #include <SPI.h>
  9. #include <SD.h>
  10. #include <Servo.h> //Require ESP32Servo, not the Arduino build in Servo.h
  11. /* Pins Definations */
  12. #define STP_DATA_PIN 4 // Stepper Shift Register DS
  13. #define STP_CLOCK_PIN 16 // Stepper Shift Register SH_CP
  14. #define STP_LATCH_PIN 17 // Stepper Shift Register ST_CP
  15. #define SERVO_SWITCH 27 //Servo to push the switch
  16. #define SERVO_COVER 14 //Servo to push the cover
  17. #define DP_CLK_PIN 32 //Display CLK
  18. #define DP_DATA_PIN 33 //Display DIN
  19. #define DP_CS_PIN 25 //Display CS
  20. #define SD_CS_PIN 5 //SD Card CS pin
  21. /* Display settings generated by trial and error. Don't touch these */
  22. #define HARDWARE_TYPE MD_MAX72XX::DR1CR0RR0_HW
  23. #define MAX_DEVICES 8
  24. /* Hardware Type Definations */
  25. Servo servoSwitchPusher;
  26. Servo servoCoverPusher;
  27. MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DP_DATA_PIN, DP_CLK_PIN, DP_CS_PIN, MAX_DEVICES);
  28. void setup() {
  29. Serial.begin(115200);
  30. /* Stepper IO */
  31. pinMode(STP_DATA_PIN, OUTPUT);
  32. pinMode(STP_CLOCK_PIN, OUTPUT);
  33. pinMode(STP_LATCH_PIN, OUTPUT);
  34. standbySteppers();
  35. /* Servo IO */
  36. servoSwitchPusher.attach(SERVO_SWITCH);
  37. servoCoverPusher.attach(SERVO_COVER);
  38. /* SD Card */
  39. // Initialize SD card
  40. if (!SD.begin(SD_CS_PIN)) {
  41. Serial.println("[Error] Unable to mount SD card");
  42. }
  43. /* Display Module */
  44. mx.begin();
  45. setDisplayBrightness(0x4);
  46. renderFrame();
  47. delay(5000);
  48. }
  49. void loop() {
  50. //Stepper test
  51. forward(50);
  52. delay(3000);
  53. backward(50);
  54. delay(3000);
  55. rotateAntiClockwise(100);
  56. delay(1000);
  57. //blink
  58. loadAndRender("/b.bin");
  59. delay(500);
  60. loadAndRender("/a.bin");
  61. delay(2000);
  62. //rotate backward
  63. rotateClockwise(100);
  64. delay(3000);
  65. //Servo test
  66. servoCoverPusher.write(90);
  67. delay(1000);
  68. servoSwitchPusher.write(180);
  69. delay(1000);
  70. servoCoverPusher.write(0);
  71. servoSwitchPusher.write(0);
  72. delay(3000);
  73. }