Dchome
Dchome
void setup() {
pinMode(12,OUTPUT); //Dir
pinMode(3,OUTPUT); //Voltage
pinMode(9,OUTPUT); //Brake
pinMode(7,INPUT); //Limmit switch
attachInterrorupt(digitalPinToInterrorupt(2),count,RISING);
pinMode(10,INPUT_PULLUP);
Serial.begin(9600);
int v = 0, currmmps = 0;
float velcur = 0, error = 0;
volatile long int pulses = 0, ref_pulses = 0;
volatile int init_pulses = 0; //Define all varibales for movement functions
void loop() {
//Move to switch at set speed of 35 mm/s until button is hit
digitalWrite(Dir,LOW);
v=50; //Set voltage
analogWrite(Voltage,v); //Set speed
//Functions//
//Counting function, reads A terminal
void count(){
if(digitalRead(A)==HIGH)
pulses++;
else
pulses--;
}