error, disabling serialEvent() for //./COM3
in
Core Library Questions
•
7 months ago
Hi...
I want to do the transition of images with respect to the intensity of light strike on LDR.
I manipulate the output of LDR from 1 to 10 in arduino and there is 10 images in processing, i want those images in processing to change with respect to the LDR output.
But i am getting this error......
error, disabling serialEvent() for //./COM3
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.serial.Serial.serialEvent(Unknown Source)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Caused by: java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:3541)
at processing.core.PApplet.image(PApplet.java:11912)
at transition_of_images.serialEvent(transition_of_images.java:65)
... 8 more
Here is my code
- import processing.serial.*;
- Serial myPort;
- PImage[] imgs;
- int nbr_of_images;
- float transitionFrames = 30;
- int displayFrames = 50;
- float fadeValue = 0;
- float img_Actual;
- float img_Next;
- void setup() {
- size(1440, 900);
- nbr_of_images = 10;
- imgs = new PImage[nbr_of_images];
- println(Serial.list());
- // print a list of all available ports
- myPort = new Serial(this, Serial.list()[1], 9600);
- myPort.bufferUntil('\n');
- for (int i = 0; i < nbr_of_images; i++)
- {
- imgs[i] = loadImage(nf(i, 2) + ".JPG");
- }
- }
- void draw () {
- // everything happens in the serialEvent()
- }
- void serialEvent (Serial myPort) {
- // get the ASCII string:
- String inString = myPort.readStringUntil('\n');
- // convert to an int and map to the screen height:
- float inByte = float(inString);
- println(inByte);
- // full opacity for image in background
- tint(255);
- image(imgs[int(img_Actual)], 0, 0, width, height);
- // fade foreground-image using tint()
- tint(255, lerp(0, 255, fadeValue));
- image(imgs[int(img_Next)], 0, 0, width, height);
- // change image and reset fadeValue
- if (frameCount % (displayFrames) == 0)
- {
- fadeValue = 0;
- img_Actual = img_Next;
- img_Next = inByte;
- }
- // increase opacity of second image
- fadeValue = fadeValue+1/transitionFrames;
Need your valuable suggestions...
Thanking you in anticipation
1