0% found this document useful (0 votes)
15 views1 page

3.3B Flow

The code controls a motor by reading encoder position values over time to calculate speed and position. It runs the motor forward and backward in a loop, recording the encoder values, time, speed, and position each time, and sending the data over serial.

Uploaded by

Payek Rizqeen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

3.3B Flow

The code controls a motor by reading encoder position values over time to calculate speed and position. It runs the motor forward and backward in a loop, recording the encoder values, time, speed, and position each time, and sending the data over serial.

Uploaded by

Payek Rizqeen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

void 

loop()

motorFoward()

newposition = encoder0Pos

  vel =
newtime = millis()   (newposition-oldposition) *
  1000 /(newtime-oldtime);

pos = (newposition)

  Serial.print ("speed = ");
  erial.println (vel);
  Serial.print ("Time = ");
data()   Serial.println (newtime);
  Serial.print ("position =
  ");
  Serial.println (pos);

oldposition = newposition

oldtime = newtime

delay(250)

motorBackward()

newposition = encoder0Pos

newtime = millis()

vel = (newposition - oldposition)   1000 / (newtime - oldtime)

pos = (newposition)

  Serial.print ("speed = ");
  Serial.println (vel);
  /Serial.print ("Time =
data()
  ");Serial.println (newtime);
  Serial.print ("position =
  "); Serial.println (pos);

oldposition = newposition

oldtime = newtime

delay(250)

void doEncoder()

digitalRead(encoder0PinA) == digitalRead(encoder0PinB)

 True   False 

encoder0Pos++ encoder0Pos--

void data()

Serial.print("Speed =")

Serial.print(vel)

Serial.print(",")

Serial.print("Time = ")

Serial.print(newtime)

Serial.print (",")   Serial.println (newtime);

Serial.print ("position = ")

Serial.println (pos)

You might also like