i have to make a speedometer for an excersise on school.
my mousewheel turns when the wheel of my bike is turning.
i tried a couple of things and it works a little.
the problem is when is stop bicycling the meter doesn't stop directly and when i cycle with the same speed the meter gives once a time an double variable. ( when it is 10.0 he said 20.0)
can someone help me, or can someone give some advice?
this is my code:
float aantal = 0;
int frames = 0;
float snelheid = 0;
float hoogste = 0;
float totaal = 0;
PImage img;
void setup(){
frameRate(60);
size(2560, 720);
textSize(30);
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
mouseWheel(evt.getWheelRotation());
}});
}
void draw() {
println(frameCount);
if (frameCount % 2==0){
println("jaa");
snelheid = aantal/1.0;
if( snelheid > hoogste){
hoogste = snelheid;
totaal = hoogste;
aantal=0.0;
}
else{
hoogste = snelheid;
totaal = hoogste;
aantal=0.0;
}
}
text(snelheid, 450, 30);
text(totaal, 600, 30);
println(snelheid);
if(snelheid <= 1.0 || totaal <= 1.0){
img = loadImage("led1.jpg");
image(img, 0, 0, 1280, 720 );
img.loadPixels();
text(totaal, 600, 30);
text(snelheid, 450, 30);
}
if(snelheid >= 1.5 || totaal >= 1.5){
img = loadImage("led2.jpg");
image(img, 0, 0, 1280, 720 );
img.loadPixels();
text(totaal, 600, 30);
text(snelheid, 450, 30);
}
if(snelheid >= 2.0 || totaal >= 2.0){
img = loadImage("led3.jpg");
image(img, 0, 0, 1280, 720 );
img.loadPixels();
text(totaal, 600, 30);
text(snelheid, 450, 30);
}
if(snelheid >= 2.5 || totaal >= 2.5){
img = loadImage("led4.jpg");
image(img, 0, 0, 1280, 720 );
img.loadPixels();
text(totaal, 600, 30);
text(snelheid, 450, 30);
}
if(snelheid >= 2.5 || totaal >= 2.5){
img = loadImage("led5.jpg");
image(img, 0, 0, 1280, 720 );
img.loadPixels();
text(totaal, 600, 30);
text(snelheid, 450, 30);
}
if(snelheid >= 3.0 || totaal >= 3.0){
img = loadImage("led6.jpg");
image(img, 0, 0, 1280, 720 );
img.loadPixels();
text(totaal, 600, 30);
text(snelheid, 450, 30);
}
}
void mouseWheel(int delta) {
if(delta >= 1 || delta <= -1){
aantal = aantal +1.0;
}
}