|
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_MotorShield AFMS2 = Adafruit_MotorShield();
Adafruit_StepperMotor *myStepMotor_1 = AFMS.getStepper(200, 1);
Adafruit_StepperMotor *myStepMotor_2 = AFMS2.getStepper(200, 2);
Adafruit_7segment matrix = Adafruit_7segment();
void setup(){
Serial.begin(9600);
AFMS.begin(8000);
AFMS2.begin(8000);
pinMode(0, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
myStepMotor_1->setSpeed(250);
myStepMotor_2->setSpeed(500);
#ifndef __AVR_ATtiny85__
Serial.begin(9600);
#endif
matrix.begin(0x73);
pinMode(8, OUTPUT); // sets the digital pin as output
}
void loop()
{
displayCoilSize();
int forwardButton = digitalRead(0);
int backwardButton = digitalRead(2);
if (forwardButton == LOW){
threadCoil();
}
else if (backwardButton == LOW){
runCartReverse();
}
else{
// No buttons being pressed = all motors halt
myStepMotor_1->step(0,FORWARD, DOUBLE);
myStepMotor_2->step(0,FORWARD, DOUBLE);
}
// myStepMotor_1->step(5,FORWARD, DOUBLE);
// myStepMotor_2->step(15,FORWARD, DOUBLE);
}
//void displayCoilSize(){
// // Prints voltage across POT at A0 and prints to the seven seg... I think...
// digitalWrite(8,HIGH);
// int sensorValue = analogRead(A0);
// float voltage = sensorValue * (5.0 / 1023.0);
// int intVoltage = voltage * 1000;
/* CONVERT VOLTAGE TO COIL SIZE */
// if ((voltage > 4.5) && (voltage <= 5)){
// matrix.print(1, DEC);
// }
// else if ((voltage > 4.0) && (voltage <= 4.5)){
// matrix.print(2, DEC);
// }
// else if ((voltage > 3.5) && (voltage <= 4.0)){
// matrix.print(3, DEC);
// }
// else if ((voltage > 3.0) && (voltage <= 3.5)){
matrix.print(4, DEC);
}
else if ((voltage > 2.5) && (voltage <= 3.0)){
matrix.print(5, DEC);
}
else if((voltage > 2.0) && (voltage <= 2.5)){
matrix.print(6, DEC);
}
else{
matrix.printError();
}
matrix.printFloat(voltage);
matrix.writeDisplay();
delay(500);
}
void threadCoil(){
myStepMotor_1->step(5,FORWARD, DOUBLE);
myStepMotor_2->step(15,FORWARD, DOUBLE);
}
void runCartReverse(){
myStepMotor_1->step(0,FORWARD, DOUBLE);
myStepMotor_2->step(15,BACKWARD, DOUBLE);
}
有LED的控制,还有两个马达的控制,导入以后只有LED工作,马达完全没反应。
|
|