Hey guys!
I'm far from an experienced Arduino guy but sometimes it can come in handy with what I do. I got an Assignment due in like 4h and I've been trying to figure out why this is not working.
Short info about the assignment, it's a machine that got a "lift" which have a bottom switch and a top switch. When the bottom switch is switched on (momentarily), a variable says "run lift" until it hits the top. Very simple but I have no idea what I'm doing wrong.
Here is the code that I've been working with, not surprised if there is heaps of misstakes in general but hey, i just want it to run.
(The motors are connected to a transistor etc. but that should be fine)
Belt part at the end is just another part of the machine.... It needs to run for like 2sec.
Would appreciate help a lot =(
EDIT: The problem I mainly had was to change the state of liftState. It is always 1, or HIGH of some reason....
const int liftBottom = 5;
const int liftTop = 6;
const int beltSw = 7;
const int lift = 10;
const int belt = 9;
int liftState = LOW;
int val = 0;
int valTop = 0;
int valBelt = 0;
int valLift = 0;
int tempTest = 0;
void setup() {
Serial.begin(9600);
pinMode(liftBottom, INPUT);
pinMode(liftTop, INPUT);
pinMode(beltSw, INPUT);
pinMode(lift, OUTPUT);
pinMode(belt, OUTPUT);
}
void loop() {
tempTest = digitalRead(liftState);
Serial.println(tempTest);
val = digitalRead(liftBottom);
valTop = digitalRead(liftTop);
////___________Check the state of the lift______
if (val == HIGH) {
// digitalWrite(liftState, HIGH);
analogWrite(lift, 255);
//Serial.println("ON");
}
else if (valTop == HIGH){
// digitalWrite(liftState, LOW);
analogWrite(lift, 0);
//Serial.println("OFF");
}
///__________________________LIFT CONTROLLER
valLift = digitalRead(liftState);
if (valLift == HIGH) {
analogWrite(lift, 255);
}
else{
analogWrite(lift, 0);
}
valBelt = digitalRead(beltSw);
if (valBelt == HIGH) {
analogWrite(belt, 255);
}
else{
analogWrite(belt, 0);
}
}