Skip to content

Commit

Permalink
Testing motor encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateo-S committed Mar 18, 2019
1 parent a9589f8 commit 44eb023
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
14 changes: 8 additions & 6 deletions chairmans2019.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
Pin 21 - SCL (Trellis)
Pin 42 - Din (LED Strip)
Pin A2 - INT (Trellis)
Power ┌──>Trellis 5V
Pin A7 - Seat motor hall
Power ┌──>Trellis 5V
┌─>5V──>Breadboard 5V Rail┼──>LED Strip 5V
Robot Battery─>Breaker─>PDP─┤ └──>Arduino Vin
└─>40A─>Victor─>CIM
Expand Down Expand Up @@ -93,6 +94,7 @@ void setup() {

Serial.println("Attaching CIM as Servo");
cim.attach(CIM_PIN);
cim.write(90);
}

void loop() {
Expand All @@ -105,7 +107,7 @@ void loop() {

// Turn a pressable button off then on when pressed
for (int i = 0; i < TRELLIS_NUM_KEYS; i++) {
if (trellis.isKeyPressed(i) && (i < 7 || i == 12) || i == 15)) {
if (trellis.isKeyPressed(i) && (i < 7 || i == 12 || i == 15)){
button = i;
trellis.clrLED(i);
delay(200);
Expand Down Expand Up @@ -154,11 +156,11 @@ void increment(int i) {
for (int seg = 0; seg < nSegments; seg++) {
originalValues[seg] = getSegment(seg);
if (seg < stage) {
endValues[seg] = past;
endValues[nSegments-1-seg] = past;
} else if (seg == stage) {
endValues[seg] = current;
endValues[nSegments-1-seg] = current;
} else {
endValues[seg] = future;
endValues[nSegments-1-seg] = future;
}
}
Serial.println("LED Destinations calculated");
Expand Down
40 changes: 40 additions & 0 deletions motorTest/motorTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <Servo.h>

int analogPin = A7; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
int val = 0; // variable to store the value read
Servo cim;
const int CIM_PIN = 9;
int i = 0;

void setup() {
Serial.begin(9600); // setup serial
pinMode(analogPin, INPUT);
cim.attach(CIM_PIN);
cim.write(59);
Serial.println("Start");
delay(2000);
}
int prev = 0;
int curr = 0;
void loop() {
prev = curr;
curr = analogRead(analogPin);
Serial.println(i);
// val = analogRead(analogPin); // read the input pin
// Serial.println(val); // debug value
if(curr > 500){
i++;
delay(20);
// Serial.println(i);
}
if(i > 174){
i = 0;
cim.write(90);
Serial.println("Stop");
delay(4000);
} else {
cim.write(59);
}
//delay(200);
}

0 comments on commit 44eb023

Please sign in to comment.