JugueBot Code Wheel Encoders #define outputA 6 #define outputB 7 int counter = 0; int aState; int aLastState; void setup() { pinMode (outputA,INPUT); pinMode (outputB,INPUT); Serial.begin (9600); // Reads the initial state of the outputA aLastState = digitalRead(outputA); } void loop() { aState = digitalRead(outputA); // Reads the "current" state of the outputA // If the previous and the current state of the outputA are different, that means a Pulse has occured if (aState != aLastState){ // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise if (digitalRead(outputB) != aState) { counter ++; } else { ...
ULTRASONIC SENSOR #include <Servo.h> #define speedPinR 9 // RIGHT WHEEL PWM pin D45 connect front MODEL-X ENA #define RightMotorDirPin1 22 //Front Right Motor direction pin 1 to Front MODEL-X IN1 (K1) #define RightMotorDirPin2 24 //Front Right Motor direction pin 2 to Front MODEL-X IN2 (K1) #define LeftMotorDirPin1 26 //Left front Motor direction pin 1 to Front MODEL-X IN3 ( K3) #define LeftMotorDirPin2 28 //Left front Motor direction pin 2 to Front MODEL-X IN4 ( K3) #define speedPinL 10 // Left WHEEL PWM pin D7 connect front MODEL-X ENB #define speedPinRB 11 // RIGHT WHEEL PWM pin connect Back MODEL-X ENA #define RightMotorDirPin1B 5 //Rear Right Motor direction pin 1 to Back MO...
Comments
Post a Comment