Ghostbusters 2 Dancing Toaster

Hey there I am working on a dancing toaster from Ghostbusters 2 lol

I have your RF fob with 4 buttons, the receiver, a UNO, wave shield and some Neopixels all from adafruit

I have two questions I need when button C is pressed the first time it turn the Neopixels to a Pink (255,0,170) then when pressed again it go green (0,255,0) then when pressed a third time it turn them off, having problems with the switch case for that

second question is I want button D when pressed to play the Jackie Wilson song and then when pressed again it stop the song

Button A triggers a relay for a actuator
then Button B triggers a sequence of Relays for the actuators to make it dance around.

I will attach my code so far ( I haven’t got to the wave shield yet)

Basically I need help with the multiple button press functions

Toaster.ino (3.23 KB)

Have a read on how to post your code with tags

I need help with the multiple button press functions

The state change detection example may be helpful. Use the buttonPushCounter variable to choose the function with switch case or if statements.

ok I see that part now

if (buttonState == HIGH) {
buttonPushCounter++;

Switch (buttonPushCounter)

that correct so far?

how do I have it loop back to case 0 after 3?

this is what I put
but when I push the button it looks like case 1 flashes then goes off

if (RFBUTTONCSTATE == HIGH){
BUTTONCPRESS++;
if(BUTTONCPRESS>=3){
BUTTONCPRESS=0;
}
}
switch (BUTTONCPRESS) {
case 0: for(int i=0;i<16;i++){
pixels.setPixelColor(i, pixels.Color(0,0,0));
pixels.show();}
break;

case 1:for(int i=0;i<16;i++){
pixels.setPixelColor(i, pixels.Color(255,0,175));
pixels.show();}
break;

case 2:for(int i=0;i<16;i++){
pixels.setPixelColor(i, pixels.Color(0,255,0));
pixels.show();}
break;

that correct so far?

Looks good.

how do I have it loop back to case 0 after 3?

set buttonPushCounter to 0 at the end of case 3. Or after buttonPushCounter++ test for buttonPushCounter > 3 and reset buttonPushCounter to 0.

Note that the state change detect example is written for an active high switch (switch pulled to ground when not pressed and high when pressed) and your switches are wired active low (low when pressed). You need to change the logic in your sketch to reflect that.

Change

  if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;

To

  if (buttonState == LOW) {
      // if the current state is LOW then the button went from off to on:
      buttonPushCounter++;

And so on.

|500x384

This will help for real

thanks for the tip about posting code

this is what I have and it only flashes case 1 on as long as I am holding the button

if (RFBUTTONCSTATE == HIGH){
  BUTTONCPRESS++;
  if(BUTTONCPRESS>=3){
    BUTTONCPRESS=0;
  }
}
switch (BUTTONCPRESS) {
   case 0: for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0));
    pixels.show();}
    break;
   
   case 1:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(255,0,175));
    pixels.show();}
    break;
    
   case 2:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,255,0));
    pixels.show();}
    break;
}

and yes it is suppose to trigger on HIGH as its coming from a RF Button and chip

The state change example (linked in an earlier reply) might be the solution. That will allow BUTTONCPRESS to change when the signal becomes HIGH not when it is HIGH.

Got it!!

if (RFBUTTONCSTATE != RFBUTTONCLASTSTATE){
    if (RFBUTTONCSTATE == HIGH){
        RFBUTTONCPUSHCOUNTER++;
  delay(50);
  }
}
if(RFBUTTONCPUSHCOUNTER>=3){
  RFBUTTONCPUSHCOUNTER=0;
}

switch (RFBUTTONCPUSHCOUNTER) {
   case 0: for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0));
    pixels.show();}
    break;
   
   case 1:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(255,0,175));
    pixels.show();}
    break;
    
   case 2:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,255,0));
    pixels.show();}
    break;

}

At some point (before you read in a new current state) you should save the current state to the last state variable.

ya lost me
sorry I am super new at this

From the state change detection example:

delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;

so like this?

if (RFBUTTONCSTATE != RFBUTTONCLASTSTATE){
    if (RFBUTTONCSTATE == HIGH){
      RFBUTTONCPUSHCOUNTER++;
      delay(50);
   RFBUTTONCLASTSTATE = RFBUTTONCSTATE;
  }
}
if(RFBUTTONCPUSHCOUNTER>=3){
  RFBUTTONCPUSHCOUNTER=0;

I do it like below. You only need to save the last state if the state has changed.

if (RFBUTTONCSTATE != RFBUTTONCLASTSTATE)
{
   if (RFBUTTONCSTATE == HIGH)
   {
      RFBUTTONCPUSHCOUNTER++;
      delay(50);
      RFBUTTONCLASTSTATE = RFBUTTONCSTATE;
   }

   if (RFBUTTONCPUSHCOUNTER >= 3)
   }

when i copy in your code it only goes to the first case then doesn't do anything past that

My apologies. I put the saving of the last state in the wrong place.

if (RFBUTTONCSTATE != RFBUTTONCLASTSTATE)
{
   if (RFBUTTONCSTATE == HIGH)
   {
      RFBUTTONCPUSHCOUNTER++;
      delay(50);      
   }

   RFBUTTONCLASTSTATE = RFBUTTONCSTATE;

   if (RFBUTTONCPUSHCOUNTER >= 3)
   }

that works great thanks!!!

what do you know about adafruit products having one more issue then i think i am done

its the wave shield i am having issues with

I have zero experience with the wave shield, but still may be able to help. What is the issue?

i have all three of them stacked and its not working

from what i see the wave uses pins 7,6,4,3 and so i have the 4 RF buttons on A0,A1,A2,A3 and the 4 relays on 10,11,12,13 and the Neopixel on pin 5

the wave sheild is the only thing not working but if i take the neopixel off the stack it works

I found this in the faq for the Adafruit wave shield. Is that your shield?

What pins are used by the shield? Pins 13, 12, 11 are always used by the SD card (they are the only pins that have a high speed SPI interface). Then there are 5 other pins used to talk to the DAC and SD card, but they can be set to connect to any arduino pin. However, by default, the library is configured to use pins 10 (for SD card) and pins 2, 3, 4 and 5 for the DAC. To chanage these pins requires modifying the library - the pins are referenced by their 'hardware' pin names (ie PORTD, etc) not by arduino pins.

That means pins 6, 7, 8, 9 and the 6 analog in pins (also known as digital i/o pins 14-20) are available.

Note that to use SPI, pin 10 must be set to OUTPUT.