We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to pull up an Gif based on data from a bluetooth sensor.
What I would like for to happen is -Data is passed from sensor -Based on the range a number is generated -"number".gif is displayed - 5 sec delay - Repeat
(all the gifs are pre-loaded in a data folder and numbered 1.gif..and so on)
Any help is much appreciated
Thanks in advance!
import gifAnimation.*;
import neurosky.*;
import org.json.*;
Gif loopingGif;
ThinkGearSocket neuroSocket;
int attention=10;
int meditation=10;
int rand;
void setup() {
size(600,600);
ThinkGearSocket neuroSocket = new ThinkGearSocket(this);
try {
neuroSocket.start();
}
catch (Exception e) {
//println("Is ThinkGear running??");
}
smooth();
//noFill();
font = createFont("Verdana",12);
textFont(font);
if (attention<=30) {
rand = int(random(1,5)); //HERE YOU CHOOSE BETWEEN 10 DIFFERENT IMAGES
String fn= ((rand) + ".gif"); //CALL YOUR FUNCTION 'takerandomimage'
loopingGif = new Gif(this, fn);
loopingGif.loop();
}
else {
rand = int(random(5,9)); //HERE YOU CHOOSE BETWEEN 10 DIFFERENT IMAGES
String fn= ((rand) + ".gif"); //CALL YOUR FUNCTION 'takerandomimage'
loopingGif = new Gif(this, fn);
loopingGif.loop();
}
}
void poorSignalEvent(int sig) {
println("SignalEvent "+sig);
}
public void attentionEvent(int attentionLevel) {
println("Attention Level: " + attentionLevel);
attention = attentionLevel;
}
void meditationEvent(int meditationLevel) {
println("Meditation Level: " + meditationLevel);
meditation = meditationLevel;
}
void draw() {
image(loopingGif, 0, 0);
}
void stop() {
neuroSocket.stop();
super.stop();
}
Answers
this means that this part belongs in draw(), not in setup() :
also you need a timer that tells you if the 5 seconds are over.
the timer controls a var displayMyGif
and when 5 secs are over, say displayMyGif = false;
when displayMyGif == false do the if and else clause above
when displayMyGif == true do
image(loopingGif, 0, 0);
all in draw()
later you want to load an array of gif in setup() that you use in draw()
Thanks so much @chrisir!
would that look something like this (apologies, I'm still very much a beginner)
absolutely
I miss setup() somehow
make sure you display the image first
maybe by placing line 7 at the very end or so
I think that's working better but now I get a NullPointerException for line 28?
that's right
the if clause
if (attention<=30) {
must be run once.... otherwise loopingGif is empty. Bad.can't you say
difference = 12000;
in setup so thatif (difference > interval) {
is true initially?You're totally right- I just tried that but it gives me a blank canvas, I can see values coming in from the sensor but no Gifs appear corresponding to them
Much confusion ensues...
post entire code pls
@chrisir- I need you to know you're a life saver right now
I made some changes to the timer and now I atleast see a Gif at first, but it doesn't change with incoming data/time- also it breaks if you increase the interval
delete line 87 maybe
it resets all the time. Bad.
this timer works:
(since I don't have gifs or the libs, it's just printing. But should do the job)
;-)
YASSS!! Thank you so so much! ^:)^
I have eyes like an eagle.
;-)
Indeed you do B-)
Absolute last question- @chrisir
If I wanted a Gif (the same Gif) to flash in between every new Gif that is loaded-
Where would I put that? I'm loading it in my Setup() as follows-:
And then trying variations in my actual code but I get nothing?
since we have 3 situations now we use states