hi
Im working with jeopardy gamestyle thing. three buttons, three lights and three diffrent sounds for each player. When the player who presses his/hers button first it blocks the other buttons and the players light and sound shines and plays. when all buttons are relased the winners light shine for about 5 seconds and then it turns off. the lights are dmx contolled and the mp3 player uses digital inputs for diffrent sounds.
if found a great code on the internetz that did somw of this. actually every thing is almost working but i dont know where to put the delay for the delayed light without delaying the winner sensing function. in the code example i have put the delay where i think it would be but it is not working there. thats why i need to know where to put the delay()?
this where i have put it.
void dmxOff()
{
delay(5000);
int i;
for (i = 0; i < 3; i++)
DmxSimple.write(DMXchannel[i], 0);
Serial.print("value 0 channel:");
Serial.println(DMXchannel[i]);
}
the whole code
//
// This sketch implements a "Jeopardy" style contestant response tiebreaker.
//
// Each contestant has a toggle switch. When they know the answer,
// they flip it on. This turns on the corresponding light.
// The light for the first person to flip their switch on blinks.
//
// Turning all of the switches off resets it.
//
// J. Peterson, Apr '11
//
// then modify to work with dmx lighting and cc triggerd mp3 player by Gustaf Gagge
#include <DmxSimple.h>
// The digital out to relay and the to mp3 player
int Digitalout[3] = {13, 12, 11};
//the witch dmx channel to output
int DMXchannel[3] = {1,2,3};
// The toggle switches connect the input to ground when closed.
int Switches[3] = { 10, 9, 8 };
// Set to -1 when no winner set.
int winner;
void setup()
{
DmxSimple.usePin(3);
DmxSimple.maxChannel(3);
Serial.begin(9600);
int i;
for (i = 0; i < 3; i++)
{
pinMode(Digitalout[i], OUTPUT);
pinMode(Switches[i], INPUT);
digitalWrite(Switches[i], HIGH); // Enable pullup
}
winner = -1;
DigitaloutOFF();
dmxOff();
}
void DigitaloutOFF()
{
int i;
for (i = 0; i < 3; i++)
digitalWrite( Digitalout[i], LOW);
}
void dmxOff()
{
delay(5000);
int i;
for (i = 0; i < 3; i++)
DmxSimple.write(DMXchannel[i], 0);
Serial.print("value 0 channel:");
Serial.println(DMXchannel[i]);
}
int invert( int value )
{
return value == HIGH ? LOW : HIGH;
}
void loop()
{
int i;
if (winner == -1)
{
// Scan the switches looking for a winner
for (i = 0; (i < 3) && (winner == -1); i++)
if (digitalRead( Switches[i] ) == LOW)
winner = i;
}
else
{
for (i = 0; i < 3; i++)
{
if (i == winner)
{
//turn the winners light on
{digitalWrite( Digitalout[winner], HIGH );
DmxSimple.write(DMXchannel[winner], 255);
Serial.print("value 255 channel:");
Serial.println(DMXchannel[i]);
}
}
else // Turn loser's lights on if switches are on
digitalWrite( Digitalout[i], invert( digitalRead( Switches[i] )));
DmxSimple.write(DMXchannel[i], invert( digitalRead( Switches[i] )));
}
}
// Check to see if all the switches are off,
// and reset the winner & lights if so.
if ((digitalRead( Switches[0] ) == HIGH)
&& (digitalRead( Switches[1] ) == HIGH)
&& (digitalRead( Switches[2] ) == HIGH))
{
winner = -1;{
DigitaloutOFF();
dmxOff();
}}
}