Go Down

Topic: Really need help with Circuit (Read 618 times) previous topic - next topic

Digiza

Hey guys, OK im loosing my mind here.

Im using a virtual applet that shows the application is working.
Code: [Select]

//Save some memory, use bytes and booleans rather than ints for pin numbers and pin states. (pin numbers are <255, so an int isnt needed)
const byte buttonPin = 9;             // the number of the pushbutton pin

// variables will change:
boolean buttonState = 0;                  // Variable for reading the pushbutton status
byte ledPin = 0;
boolean loopwait = 0;

#define maxLEDs 9 //This replaces anything which say 'maxLEDs' with the number 9
byte ledPins[maxLEDs] = {0,1,2,3,4,5,6,7,8}; //set your LED pins here

void setup() {
  //pinMode(ledPin, OUTPUT);       // Initialize the LED pin as an output:
  pinMode(buttonPin, INPUT);     // Initialize the pushbutton pin as an input:
  for (byte i = 0; i < maxLEDs; i++){
    pinMode(ledPins[i], OUTPUT); //Set all of the different LEDs to outputs.
  }
}

void loop(){
  buttonState = digitalRead(buttonPin);  // read the state of the pushbutton value:
  if (buttonState == HIGH) {                 // check if the pushbutton is pressed.
    if (loopwait == 0) {
      // turn LED on:   
      byte randomNumber = random(100); //You want all statements to check against the same number, not generate a new one for each elseif() statement
      if (randomNumber < 20){
        ledPin = 0;
      }
      else if (randomNumber < 40){
        ledPin = 1;
      }
      else if (randomNumber < 60){
        ledPin = 2;
      }
      else if (randomNumber < 70){
        ledPin = 3;
      }
      else if (randomNumber < 80){
        ledPin = 4;
      }
      else if (randomNumber < 90){
        ledPin = 5;
      }
      else if (randomNumber < 94){
        ledPin = 6;
      }
      else if (randomNumber < 98){
        ledPin = 7;
      }
      else if (randomNumber < 101){
        ledPin = 8;
      }
      digitalWrite(ledPins[ledPin], HIGH);
      loopwait = 1;
    }
  } else {
    loopwait = 0;
    digitalWrite(ledPins[ledPin], LOW);       // turn LED off:
  }
}


but I cant get the wiring right at all on this. And I cant find anything at the moment. Can anyone help, I keep getting it running random at massive speed when switch is open and when closed it stops.

Can anyone assist either my code is wonky or the wiring is wonky.

Digiza

This Basically the Circuit I have currently.  =(
Im really sucking at this. I gotta study more.

https://www.dropbox.com/s/q5fv9qehnxwnb05/Arduino.PNG

retrolefty

#2
Jul 09, 2012, 10:07 pm Last Edit: Jul 09, 2012, 10:15 pm by retrolefty Reason: 1

This Basically the Circuit I have currently.  =(
Im really sucking at this. I gotta study more.

https://www.dropbox.com/s/q5fv9qehnxwnb05/Arduino.PNG


First thing is that you need a pull-down resistor wired from pin D9 to ground, 10k ohms will work fine. Second thing is all those LED each require a series current limiting resistor of around 200-500 ohm each, then remove the single 10 (?) ohm resistor. As you have it the leds will get dimmer and dimmer as you light more then one at a time.

Lefty

Digiza

Hey retrolefty,

The lights will only have one light at a time with the application thats running (well it is supposed to) this was why I only utilized one Resistance.
Ill try adding the resistor to the Pin 9 from button, hopefully this solves my issue.

Thanks.

Grumpy_Mike

Do as you are told with the LEDs, or at least change the 10R to at least 220R.

Go Up