Detection sensor and looping animation
in
Integration and Hardware
•
2 years ago
We would like to know how we can call a function within the draw loop which is activated by a Photo Interrupter sensor (high/low). The function is some sort of animation which is build from moving vertexes. When activated this function has to last for about 10 seconds. When the timer has finished the function should be called again.
While activating the sensor, the function loops only for 1 frame ( < 1 sec.). How do I solve this?
When there are any questions, please ask.
Thanks for your help!
When there are any questions, please ask.
Thanks for your help!
- // read the sensor input pin:
- buttonState = arduino.digitalRead(digitalPin);
- // compare the buttonState to its previous state
- if (buttonState != lastButtonState) {
- // if the state has changed, increment the counter
- if ((buttonState == Arduino.HIGH)) {
- // if the current state is HIGH then the sensor
- // wend from off to on:
- startCard();
- println("on");
- }
- }
- // save the current state as the last state,
- //for next time through the loop
- lastButtonState = buttonState;
- }
- void startCard() {
- timer.start();
- showCard = true;
- for(cardI = 0; cardI < numC; cardI++) {
- BusinessCard card = (BusinessCard) businessCards[cardI];
- card.run();
- card.follow(vectorField);
- }
- if (timer.isFinished()) {
- for(i = 0; i < numP; i++) {
- Particle p = (Particle) particles[i];
- p.speedUpParticle(normalSpeed);
- p.run();
- p.follow(vectorField);
- }
- } else {
- for(i = 0; i < numP; i++) {
- Particle p = (Particle) particles[i];
- p.speedUpParticle(speedI);
- p.run();
- p.follow(vectorField);
- }
- }
- }
1