Advertisement
pleasedontcode

WiFi Motorization rev_03

May 18th, 2024
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: WiFi Motorization
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-19 00:25:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Ensure the motors are controlled individually: Set */
  21.     /* speed, direction, and movement for each motor */
  22.     /* independently using L298NX2 library functions. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <L298NX2.h>    // https://github.com/AndreaLombardo/L298N
  27. #include <WiFiProvisioner.h>    // https://github.com/SanteriLindfors/WiFiProvisioner
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  34. const uint8_t IN1_A = 5;
  35. const uint8_t IN2_A = 6;
  36. const uint8_t IN1_B = 7;
  37. const uint8_t IN2_B = 8;
  38.  
  39. /***** DEFINITION OF PWM OUTPUT PINS *****/
  40. const uint8_t EN_A = 3;
  41. const uint8_t EN_B = 9;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. L298NX2 motors(EN_A, IN1_A, IN2_A, EN_B, IN1_B, IN2_B);
  45. WiFiProvisioner::WiFiProvisioner provisioner;
  46.  
  47. void setup(void)
  48. {
  49.     // put your setup code here, to run once:
  50.     Serial.begin(9600);
  51.     while (!Serial)
  52.     {
  53.         // do nothing
  54.     }
  55.     motors.setSpeed(80);
  56.  
  57.     // Initialize WiFiProvisioner object
  58.     provisioner.resetCredentials();
  59.     provisioner.enableSerialDebug(true);
  60.     provisioner.setInputCheckCallback(inputValidationCallback);
  61.     provisioner.setFactoryResetCallback(factoryReset);
  62.     provisioner.setOnProvisionCallback(onProvision);
  63.     provisioner.INPUT_TEXT = "Enter custom value:";
  64.     provisioner.INPUT_PLACEHOLDER = "Custom value";
  65.     provisioner.INPUT_LENGTH = "4";
  66. }
  67.  
  68. void loop(void)
  69. {
  70.     // put your main code here, to run repeatedly:
  71.     motors.forward();
  72.     printSomeInfo();
  73.     delay(3000);
  74.  
  75.     motors.stop();
  76.     printSomeInfo();
  77.     delay(3000);
  78.  
  79.     motors.setSpeedA(255);
  80.     motors.setSpeedB(90);
  81.     motors.backwardA();
  82.     motors.backwardB();
  83.     printSomeInfo();
  84.     delay(3000);
  85.  
  86.     motors.stop();
  87.     printSomeInfo();
  88.     motors.setSpeedA(90);
  89.     motors.setSpeedB(255);
  90.     delay(3000);
  91. }
  92.  
  93. void printSomeInfo()
  94. {
  95.     Serial.print("Motor A is moving = ");
  96.     Serial.print(motors.isMovingA() ? "YES" : "NO");
  97.     Serial.print(" at speed = ");
  98.     Serial.println(motors.getSpeedA());
  99.     Serial.print("Motor B is moving = ");
  100.     Serial.print(motors.isMovingB() ? "YES" : "NO");
  101.     Serial.print(" at speed = ");
  102.     Serial.println(motors.getSpeedB());
  103. }
  104.  
  105. bool inputValidationCallback(const String& input) {
  106.     // Check if the input is valid
  107.     return input == "1234";
  108. }
  109.  
  110. void factoryReset() {
  111.     Serial.println("Factory reset triggered.");
  112.     provisioner.setShowInputField(true);
  113. }
  114.  
  115. void onProvision() {
  116.     // Conditionally show the input field
  117.     bool example = false;
  118.     provisioner.setShowInputField(example);
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement