Hello,
I am working on a project to turn a sewing machine into a guitar pickup winder. Basically, what I want is to have the Arduino switching a relay on and off according to two variables, the current number of turns and the total number of turns. I want to be able to press four different buttons to set the ones, tens, hundreds, and thousands columns of the total number of turns (WindTotal) and then have a button that starts the relay until the current number of winds (WindCurrent) equals the WindTotal set. I will monitor this with a reed switch/magnet combination attached to the sewing machine foot.
My problem is that I cannot seem to get the counter to go up. In fact, the button pressing seems to accomplish nothing at all! I'm sure that my approach is flawed, but I can't for the life of me figure out how. Is there a logical ordering I have out of whack? Or am I handling the reading of the buttons incorrectly?
I do not currently have a schematic, but can upload my crude drawings if that will help anyone.
My code is as follows:
#include <LiquidCrystalFast.h>
#define Relay 0
#define OnesButt A5
#define TensButt A4
#define HundButt A3
#define ThouButt A2
int onesval = 0;
int tensval = 0;
int hundval = 0;
int thouval = 0;
#define ClearButt A1
#define TurnSwitch 9
int currentval = 0;
int totalval = 0;
int TurnClear;
#define StartButt A0
int startval = 0;
#define HaltButt 13
int haltval = 0;
int WindCurrent = 0;
int WindTotal = 0;
LiquidCrystalFast lcd(8, 7, 6, 5, 4, 3, 2); // LCD pins: RS RW EN D4 D5 D6 D7
void setup() {
// set up the LCD's number of rows and columns:
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(TurnSwitch, INPUT);
pinMode(OnesButt, INPUT);
pinMode(TensButt, INPUT);
pinMode(HundButt, INPUT);
pinMode(ThouButt, INPUT);
pinMode(ClearButt, INPUT);
pinMode(StartButt, INPUT);
pinMode(HaltButt, INPUT);
pinMode(TurnSwitch, INPUT);
}
void loop() {
lcd.clear();
startval = digitalRead(StartButt);
TurnClear = digitalRead(ClearButt);
onesval = digitalRead(OnesButt);
tensval = digitalRead(TensButt);
hundval = digitalRead(HundButt);
thouval = digitalRead(ThouButt);
if(WindTotal >> 9999){
(WindTotal == 0);
}
if(startval == HIGH){
wind();
delay(100);
}
if(TurnClear == HIGH){
(WindTotal == 0);
delay(100);
}
if(onesval == HIGH){
WindTotal++;
delay(100);
}
}
if(tensval == HIGH){
WindTotal+10;
delay(100);
}
if(hundval == HIGH){
WindTotal+100;
delay(100);
}
if(thouval == HIGH){
WindTotal+1000;
delay(100);
}
Serial.println(WindTotal);
lcd.setCursor(0, 0);
lcd.print("Current = ");
lcd.print(WindCurrent);
lcd.setCursor(0, 1);
lcd.print("Total = ");
lcd.print(WindTotal);
delay(50);
}
void wind() {
lcd.clear();
WindCurrent=0;
while(WindCurrent < WindTotal){
digitalWrite(Relay, HIGH);
currentval = digitalRead(TurnSwitch);
if (currentval == HIGH ){
WindCurrent++;
delay(30);
}
haltval = digitalRead(HaltButt);
if (haltval == HIGH){
digitalWrite(Relay, LOW);
}
lcd.setCursor(0, 0);
lcd.print("Current = ");
lcd.print(WindCurrent);
lcd.setCursor(0, 1);
lcd.print("Total = ");
lcd.print(WindTotal);
delay(20);
}
digitalWrite(Relay, LOW);
}
Thanks in advance for any tips, or if anyone can point me to a source for rewriting the trouble bits of code.