cute_useless_robot.ino 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. Cute Useless Robot (´・ω・`)
  3. Developed by tobychui
  4. Idea come from Kairoshi
  5. Board Settings:
  6. ESP32 v2.014
  7. -> ESP32 Dev Module
  8. */
  9. /* Libraries */
  10. #include <MD_MAX72xx.h>
  11. #include <SPI.h>
  12. #include <SD.h>
  13. #include <ESP32Servo.h> //Require ESP32Servo
  14. /* Pins Definations */
  15. #define STP_DATA_PIN 4 // Stepper Shift Register DS
  16. #define STP_CLOCK_PIN 16 // Stepper Shift Register SH_CP
  17. #define STP_LATCH_PIN 17 // Stepper Shift Register ST_CP
  18. #define SERVO_SWITCH 27 //Servo to push the switch
  19. #define SERVO_COVER 14 //Servo to push the cover
  20. #define DP_CLK_PIN 32 //Display CLK
  21. #define DP_DATA_PIN 33 //Display DIN
  22. #define DP_CS_PIN 25 //Display CS
  23. #define SD_CS_PIN 5 //SD Card CS pin
  24. #define TOGGLE_SWITCH 13 //Switch on top of the matrix display
  25. /* Display settings generated by trial and error. Don't touch these */
  26. #define HARDWARE_TYPE MD_MAX72XX::DR1CR0RR0_HW
  27. #define MAX_DEVICES 8
  28. /* Calibrated offset for switch pusher servo, in degrees */
  29. #define SERVO_ALIGNMENT_OFFSET -1
  30. /* Hardware Type Definations */
  31. Servo servoSwitchPusher;
  32. Servo servoCoverPusher;
  33. MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DP_DATA_PIN, DP_CLK_PIN, DP_CS_PIN, MAX_DEVICES);
  34. /* Global Variables */
  35. char animation = 'a'; //Animation ID to render
  36. bool SD_exists = true; //Keep track of the animation SD card exists
  37. void setup() {
  38. Serial.begin(115200);
  39. // Allow allocation of all timers
  40. ESP32PWM::allocateTimer(0);
  41. ESP32PWM::allocateTimer(1);
  42. ESP32PWM::allocateTimer(2);
  43. ESP32PWM::allocateTimer(3);
  44. /* Stepper IO */
  45. pinMode(STP_DATA_PIN, OUTPUT);
  46. pinMode(STP_CLOCK_PIN, OUTPUT);
  47. pinMode(STP_LATCH_PIN, OUTPUT);
  48. standbySteppers();
  49. /* Servo IO */
  50. servoSwitchPusher.setPeriodHertz(50);
  51. servoCoverPusher.setPeriodHertz(50);
  52. servoSwitchPusher.attach(SERVO_SWITCH);
  53. servoCoverPusher.attach(SERVO_COVER);
  54. servoCoverPusher.write(0);
  55. servoSwitchPusher.write(0);
  56. /* SD Card */
  57. // Initialize SD card
  58. if (!SD.begin(SD_CS_PIN)) {
  59. Serial.println("[Error] Unable to mount SD card");
  60. SD_exists = false;
  61. }
  62. /* Display Module */
  63. mx.begin();
  64. setDisplayBrightness(0x4);
  65. renderFrame(); //Render the default frame to matrix
  66. delay(5000);
  67. /* Start Dual-core processes */
  68. createSemaphore();
  69. startCoreTasks();
  70. }
  71. void loop() {
  72. //Process has been handled in tasks.ino
  73. //Do not use this loop
  74. }