trouble with moving car
in
Programming Questions
•
9 months ago
Hi this is my first arduino/ processing project, the car's speed is determined by an LDR, but somehow the effect is this instead of a normal car moving. again this is my first project, I probably made a real stupid mistake but help would be appreciated. using a arduino uno with latest stable version of processing.
here is my code:
import processing.serial.*;
import cc.arduino.*;
import ddf.minim.*;
AudioSample kick;
Minim minim;
PImage img;
int posX = 21;
int posY = 425;
boolean a = false;
Arduino arduino;
int myValue;
int buttonPin = 2;
int ledr1 = 13;
int ledr2 = 12;
int ledr3 = 4;
int ledg = 7;
int buttonState = 0;
int speaker = 8;
void setup()
{
background(0);
size(1600,850);
minim = new Minim(this);
kick = minim.loadSample("countdown.mp3");
//player.play();
img = loadImage("car.png");
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(buttonPin, arduino.INPUT);
arduino.pinMode(ledr1, arduino.OUTPUT);
arduino.pinMode(ledr2, arduino.OUTPUT);
arduino.pinMode(ledr3, arduino.OUTPUT);
arduino.pinMode(ledg, arduino.OUTPUT);
arduino.pinMode(speaker, arduino.OUTPUT);
}
void draw()
{
myValue = arduino.analogRead(0);
println(myValue);
image(img ,posX,posY, width/14, height/14);
if (arduino.digitalRead(2) == Arduino.HIGH) {
delay(1000);
kick.trigger();
arduino.digitalWrite(ledr1, arduino.HIGH);
delay(1500);
arduino.digitalWrite(ledr2, arduino.HIGH);
delay(1500);
arduino.digitalWrite(ledr3, arduino.HIGH);
a = true;
delay(1500);
arduino.digitalWrite(ledr1, arduino.LOW);
arduino.digitalWrite(ledr2, arduino.LOW);
arduino.digitalWrite(ledr3, arduino.LOW);
arduino.digitalWrite(ledg, arduino.HIGH);
delay(2000);
arduino.digitalWrite(ledg, arduino.LOW);
}
if (posX>width-110){
posX=0;
}
if (a == true){
posX=posX+myValue;
}
}
1