cute_useless_robot.ino 2.6 KB

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