We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have an animation that plays when the value read by the photoresistor on A0, drops below a threshold. Im using a continuous rotation "servo" ( 0=anticlockwise, 90=stop, 180=clockwise). The gif plays fine and the photoresistor values are coming in just fine too but the servo just wont respond. I checked the power supply and the connections. Im running standard firmata on an arduino mega.
here is the code
Animation animation1;
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
void setup() {
size(640, 360);
background(255, 204, 0);
frameRate(24);
animation1 = new Animation("BL ", 38);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
for (int i = 0; i <= 52; i++)
arduino.pinMode(i, Arduino.INPUT);
arduino.pinMode(8, Arduino.SERVO);
}
void draw() {
int pres=arduino.analogRead(0);
println(pres);
if (pres<140) {
arduino.servoWrite(8, 90);
delay(500);
animation1.display(0, 0);
}
else {
background(0);
arduino.servoWrite(8,180);
delay(500);
}
}
class Animation {
PImage[] images;
int imageCount;
int frame;
Animation(String imagePrefix, int count) {
imageCount = count;
images = new PImage[imageCount];
for (int i = 0; i < imageCount-1; i++) {
String filename = imagePrefix + nf(i) + ".jpg";
images[i] = loadImage(filename);
}
}
void display(float xpos, float ypos) {
frame = (frame+1) % imageCount;
if(frame<31)
image(images[frame], xpos, ypos);
else
frame=0;
}
int getWidth() {
return images[0].width;
}
}
Answers
Please don't post duplicates -- edit your post instead with the gear icon. This thread should be closed, answers go here:
https://forum.processing.org/two/discussion/21839/photoresistor-controlled-servo-not-responding