Closed GoogleCodeExporter closed 9 years ago
Incomplete source code.
Original comment by arduino....@gmail.com
on 2 Dec 2013 at 10:01
here is my source code... not sure why this is now invalid, as its a legitimate
issue I've been experiencing...
its a bit messy as of now, but heres the whole source code for my project.
#define BTN1 4 // GPIO definitions in Arduino - not physical pins
#define BTN2 5
#define SW1 8
#define SW2 9
#define SW3 10
#define SPK 11
#define AUD 7
const int led[4]={2,12,13,0}; // (2,3,12,13,0,6) with all LEDS onboard.
byte inputMode = 0x00; // All input (buttons and switches) states stored here
byte counter = 0;
byte counterB = 0;
boolean readingA;
boolean readingB;
boolean currentStateA = HIGH;
boolean currentStateB = HIGH; // the debounced input value
long time = 0;
int debounceCount = 10;
byte randomLed = 0;
void setup() {
for (byte i = 0; i < 3; i = i + 1) { // Array of LEDS set to outputs
pinMode(led[i], OUTPUT);
}
pinMode(BTN2,INPUT_PULLUP); // Buttons, switches inputs pulled HIGH with internal pullup resistors
pinMode(BTN1,INPUT_PULLUP);
pinMode(SW1,INPUT_PULLUP);
pinMode(SW2,INPUT_PULLUP);
pinMode(SW3,INPUT_PULLUP);
pinMode(SPK,OUTPUT); // Speaker and audio jacks set to outputs
pinMode(AUD,OUTPUT);
}
void loop() {
if(millis() != time)
{
readingA = digitalRead(BTN1);
readingB = digitalRead(BTN2);
if(readingA == currentStateA && counter > 0)
{
counter--;
}
if(readingA != currentStateA)
{
counter++;
}
if(readingB == currentStateB && counterB > 0)
{
counterB--;
}
if(readingB != currentStateB)
{
counterB++;
}
if(counter >= debounceCount){
if(readingA == LOW){
counter = 0;
currentStateA = readingA;
if(digitalRead(SW1) == LOW){
if(digitalRead(SW2) == LOW){
if(digitalRead(SW3) == LOW){
tick();
}else {
tick();
}
}else {
if(digitalRead(SW3) == LOW) {
tick();
highTone();
}else {
tick();
randomTone();
}
}
}
else {
if(digitalRead(SW2) == LOW) {
if(digitalRead(SW3) == LOW) {
tick();
pulseLed(1);
}else {
tick();
randomLight();
}
}else {
if(digitalRead(SW3) == LOW) {
tick();
toneLed(1,1);
}else{
tick();
toneLed(randomLed, (randomLed %2) );
}
}
}
}
if(counterB >= debounceCount){
if(readingB == LOW){
counterB = 0;
currentStateB = readingB;
if(digitalRead(SW1) == LOW){
if(digitalRead(SW2) == LOW){
if(digitalRead(SW3) == LOW){
tick();
tick();
}else {
tick();
tick();
}
}else {
if(digitalRead(SW3) == LOW) {
tick();
tick();
midTone();
}else {
tick();
tick();
randomTone();
}
}
}
else {
if(digitalRead(SW2) == LOW) {
if(digitalRead(SW3) == LOW) {
tick();
tick();
pulseLed(2);
}else {
tick();
tick();
randomLight();
}
}else {
if(digitalRead(SW3) == LOW) {
tick();
tick();
toneLed(2,0);
}else{
tick();
tick();
toneLed(randomLed, (randomLed %2) );
}
}
}
}
}
time = millis();
randomLed = time%4;
if(randomLed == 2){ // random RED Leds only
randomLed = 1;
}
}
}
}
void onOff(byte pin, int fallDelay, int postDelay) { // function for digital
outs
digitalWrite(pin, HIGH);
delay(fallDelay);
digitalWrite(pin, LOW);
delay(postDelay);
}
void randomLight() {
onOff(led[randomLed],750,10);
}
void pulseLed(byte ledPin) {
onOff(led[ledPin],750,10);
}
void toneLed(byte pinny, boolean lowhigh ) {
digitalWrite(led[pinny],HIGH);
if(lowhigh == LOW) {
midTone();
} else {
highTone();
}
digitalWrite(led[pinny],LOW);
}
void highTone() {
for (byte thisPin = 150; thisPin >= 10; thisPin--) {
onOff(SPK,1,1);
}
}
void midTone() {
for (byte thisPin = 100; thisPin >= 10; thisPin--) {
onOff(SPK,1,2);
}
}
void randomTone() {
randomLed /= 2;
if(randomLed == 0) {
midTone();
} else {
highTone();
}
}
void tick() {
digitalWrite(AUD,HIGH);
delayMicroseconds(100);
digitalWrite(AUD,LOW);
}
Original comment by hatchina...@gmail.com
on 2 Dec 2013 at 10:09
Do you have resistors with those LEDs?
Original comment by arduino....@gmail.com
on 3 Dec 2013 at 12:26
Original issue reported on code.google.com by
hatchina...@gmail.com
on 2 Dec 2013 at 9:24