Commit 3bdf6289 authored by 42loop's avatar 42loop
Browse files

clean up

parent 649077cc
#define debug
#include <TimerOne.h>
//constants for state machine:
......@@ -18,16 +17,13 @@ volatile int last_state=0;
String statenames[]={"idle","arm closing","patting","arm opening","paper feed"};
volatile long period=750;
#define handmax 1700
#define papermax 24000
//#define handmax 10
//volatile long period=50000;
#define handwavemax 2
#define papermax 24000
//pin definitions:
//arm motor
#define steppin_0 2
......@@ -51,9 +47,6 @@ volatile long period=750;
int inByte;
String rec="";
//byte currentmotor=5;
//volatile byte currentmotor=5;
#define armclose LOW
#define armopen HIGH
......@@ -77,18 +70,15 @@ volatile int papertime=0;
volatile bool armsens;
volatile bool trsens;
volatile bool last_trsens;
volatile bool hand_end=false;
volatile long armstepcount=0;
volatile long handstepcount=0;
volatile bool hand_end=false;
volatile byte handwavecount=3;
#define handwavemax 2
bool steppersenable=false;
void setup() {
pinMode(13, OUTPUT);
......@@ -102,11 +92,11 @@ void setup() {
digitalWrite(dirpin_0,armclose);
digitalWrite(steppin_0,HIGH);
digitalWrite(enpin_0,steppersenable);
digitalWrite(enpin_0,false);
digitalWrite(dirpin_1,handup);
digitalWrite(steppin_1,HIGH);
digitalWrite(enpin_1,steppersenable);
digitalWrite(enpin_1,false);
......@@ -163,8 +153,7 @@ void onestep(byte motor)
void(* resetFunc) (void) = 0; //declare reset function @ address 0
void timerIsr(){//timer0 interrupt 2kHz toggles pin 8
//generates pulse wave of frequency 2kHz/2 = 1kHz (takes two cycles for full wave- toggle high then toggle low)
void timerIsr(){
armsens=digitalRead(armsensor);
trsens=digitalRead(trittsensor);
......@@ -186,7 +175,6 @@ switch (state) {
dir0=armclose;
digitalWrite(enpin_0,true);
digitalWrite(enpin_1,true);
digitalWrite(dirpin_0,dir0);
onestep(0);
......@@ -194,13 +182,12 @@ switch (state) {
if (debug) {Serial.print("arm: ");Serial.println(armstepcount);}
if (armsens==LOW) {state+=1;handstepcount=0;handwavecount=0;hand_end=false;}
// statements
break;
case state_waving:
digitalWrite(enpin_0,true);
digitalWrite(enpin_1,true);
// statements
if (dir1==handup)
{handstepcount+=1;}
else
......@@ -239,8 +226,6 @@ switch (state) {
{
Serial.println("hand: last wave");
hand_end=true;
//dir1=!dir1;
}
if (handstepcount==0)
......@@ -263,8 +248,8 @@ switch (state) {
armstepcount-=1;
if (armstepcount==0) {state+=1;}
if (debug) {Serial.print("arm: ");Serial.println(armstepcount);}
// statements
break;
case state_paper:
digitalWrite(enpin_0,false);
digitalWrite(enpin_1,false);
......@@ -279,10 +264,8 @@ switch (state) {
analogWrite(paperpin,0);
}
// statements
break;
default:
// statements
break;
}
......@@ -292,39 +275,19 @@ switch (state) {
void loop() {
if (digitalRead(not_aus)==0) {resetFunc();}
if (digitalRead(not_aus)==0) {resetFunc();}
if (state!=last_state)
{
Serial.print("state: ");Serial.println(statenames[state]);
last_state=state;
}
if (state!=last_state)
{
/* if (state!=state_idle)
{
steppersenable=true;
digitalWrite(enpin_1,steppersenable);
digitalWrite(enpin_0,steppersenable);
Serial.print("ENABLE:");Serial.println(steppersenable);
}
else
{
steppersenable=false;
digitalWrite(enpin_1,steppersenable);
digitalWrite(enpin_0,steppersenable);
Serial.print("ENABLE:");Serial.println(steppersenable);
}
*/
Serial.print("state: ");Serial.println(statenames[state]);
last_state=state;
}
if (Serial.available() > 0) {
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
boolean isaxcmd=false;
if (inByte!=10) {rec+=(char)inByte;}
else
{
......@@ -352,7 +315,7 @@ if (Serial.available() > 0) {
if (cmd=="e")
{
Timer1.detachInterrupt();
Timer1.detachInterrupt();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment