I'm trying to display the amount of available spaces after a servo goes 90 degrees.
I don't get errors but what I want isn't displayed or compiled?
2nd_Update_Counter.ino (1.04 KB)
I'm trying to display the amount of available spaces after a servo goes 90 degrees.
I don't get errors but what I want isn't displayed or compiled?
2nd_Update_Counter.ino (1.04 KB)
KyleXYZ:
what I want isn't displayed or compiled?
Idk, you're the one running the code - only you know what it's outputting.
#include <LiquidCrystal.h>
#include <Servo.h>
#include <EEPROM.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
Servo servo1;
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
int currentState1 = 0;
int previousState1 = 0;
int Beschikbaar = 0;
int pos;
void setup() {
servo1.attach(11);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.begin(16, 2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.setCursor(0, 1);
lcd.print("Beschikbaar");
lcd.setCursor(4, 0);
lcd.print("Welcome");
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * 0.034 / 2;
distanceInch = duration * 0.0133 / 2;
while (distanceCm <= 10)
{ for (pos = 0; pos <= 90; pos += 90) {
servo1.write(pos);
delay(2000);
}
{
break;
}
while (pos = 90) {
(currentState1 = 1);
}
while (currentState1 = 1) {
(Beschikbaar = Beschikbaar + 1);
}
lcd.print(Beschikbaar);
}
}
Breaking down your while loop:
while(distanceCm <= 10)
{
for (pos = 0; pos <= 90; pos +=90)
{
servo1.write(pos);
delay(2000);
}
{break;}
What is your aim here? distanceCm is never updated in this loop.
What is the "{break;} doing?
while (pos = 90)
{
(currentState1 =1);
}
while (currentState1 = 1)
{
You're using assignment "=" instead of compare "==" in these.
I'm using a UltraSonic Sensor and a Servo. Whenever an object moves 10cm in front of the US Sensor the servo goes up at a 90 degree angle.
I'm trying to log how many times that happens with the integer "Beschikbaar"
KyleXYZ:
I'm using a UltraSonic Sensor and a Servo. Whenever an object moves 10cm in front of the US Sensor the servo goes up at a 90 degree angle.
I'm trying to log how many times that happens with the integer "Beschikbaar"
It looks to me like you really need to decide what you are counting. If you move the servo up while the distance is less than 10, i suspect you are moving the servo far more often than you need to, and counting a useless number of actions.
If you move the servo ONCE when the distance BECOMES less than 10, you'll count something meaningful.