Pages: [1]   Go Down
Author Topic: Billie Jean pavement (sidewalk)  (Read 697 times)
0 Members and 1 Guest are viewing this topic.
Guernsey
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Where did Leno go?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

So far I've just been dabbling with my new Arduino but I frickin' love it and I now have many ideas for projects.

I may have bitten off more than I can chew for my first project but I like to dive in at the deep end. (I'll stop with the idioms now.)

If you've seen the music video to Michael Jacksons' 'Billie Jean' you'll know the kind of thing I'm after. A series of steps each individually illuminated by an LED and each individually controlled by a IR "trip wire". As someone walks on to a step and breaks the IR beam the LED will light up that step. However I'd also like for it to illuminate the next step a split second later so as you walk down (or up) the step ahead is always lit up for you. And of course, the steps behind turns off a few milliseconds after the foot leaves it and the IR beam is reset.

I've setup a basic version of this with momentary switches as the trip wires or like pressure switches on a stepping stone and I've got a clunky sketch running but it doesn't work quite how I'd like it to. Too many if statements for starters. Plus if more than one finger steps down on my pretend stepping stones it flickers between LEDS as it runs though the loop. I thought perhaps I could use a function some how.

I have over 10 years of web developing under my belt but trying to programme when its constantly looping frazzles my brain a bit.

Anyway, I have attached a very basic diagram of my setup. Each switch is paired with the opposite LED. I'm not looking for an answer as I'll never learn that way. I'm just looking for a nudge in the right direction as the past couple of nights of staying up till 2am without much progress is starting to wear me out.

Thanks in advance for even taking the time to just read my waffle. And any advice you can give. Hopefully one day I'll be adept in Arduino enough to help others out in the future.

Cheers

Ben


* photo (2).JPG (492.78 KB, 1296x968 - viewed 14 times.)
« Last Edit: September 01, 2011, 12:56:48 pm by poor_leno » Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 30
Posts: 2246
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your schematic looks fine. How about posting the sketch?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31458
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Typical beginner circuit. It is better to have buttons connect to ground and use resistors to pull to 5V. In the arduino these are even fitted inside the chip and can be activated by a digital write high to the pin once it has been set as an input.

Why are the outputs labeled A0 to A5, these are analogue INPUTS in the arduino world, although these pins can be used as outputs but treat them as pins 14 for A0 , 15 fro A1 and so on.
« Last Edit: August 31, 2011, 11:46:26 pm by Grumpy_Mike » Logged

Guernsey
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Where did Leno go?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike, you're right, my diagram was labelled wrong. It had been a long day.

Since your posts I have now moved the push buttons to pins 0-4 for a digitalRead and I have moved the switches and resistors around as you suggested. Why is this best practice? The pins now read HIGH until a button is pressed.

I've attached a new diagram in case you'd like to see my new setup.

Thanks Chagrin, here is my sketch. I'm thinking I need to write a function that has the states of each pin passed to it and then decides which LEDs should be turned on. Anyway, here's where I am which obviously doesn't work as I'd like... I had to start somewhere I guess.


Code:
// Basic stepping stone LED sketch
//
//
//

#define led1 8  // naming the LED pins
#define led2 9
#define led3 10  
#define led4 11
#define led5 12

int trip1 = 0;   // variables to store input states
int trip2 = 0;
int trip3 = 0;
int trip4 = 0;
int trip5 = 0;

int timedelay = 0;

void setup() {
  Serial.begin(9600);
  
  pinMode(led1, OUTPUT);  // leds are OUTPUTs
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);

}

void loop() {
  
  trip1 = digitalRead(0); // read state from push buttons
  trip2 = digitalRead(1);
  trip3 = digitalRead(2);
  trip4 = digitalRead(3);
  trip5 = digitalRead(4);

  /*
  Serial.print("trip1: ");
  Serial.println(trip1, DEC);
  Serial.print("trip2: ");
  Serial.println(trip2, DEC);
  Serial.print("trip3: ");
  Serial.println(trip3, DEC);
  Serial.print("trip4: ");
  Serial.println(trip4, DEC);
  Serial.print("trip5: ");
  Serial.println(trip5, DEC);
  delay(1000);
  */
  
  // when first trip is triggered, illuminate LED on that step AND next step
  if(!trip1) {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
  }

  // when second trip is triggered, illuminate LED on that step AND next step
  if(!trip2) {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
  }

  // and so on...
  if(!trip3) {
    digitalWrite(led1, LOW);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, LOW);
  }

  if(!trip4) {
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
  }
  
  if(!trip5) {
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
  }
  
  // reset to original states and turn off all LEDs
  if(trip1 && trip2 && trip3 && trip4 && trip5) {
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
  }
  
}




Thanks for your help so far.

Ben


* photo (7).JPG (640.55 KB, 1296x968 - viewed 11 times.)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24364
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
have now moved the push buttons to pins 0-4
I notice you have a "Serial.begin" in your sketch, but you've just used your serial interface pins for the first two inputs.
It isn't a problem, but may make future debugging tricky.

When you find yourself repeating (or almost) yourself, like this
Code:
trip1 = digitalRead(0); // read state from push buttons
  trip2 = digitalRead(1);
  trip3 = digitalRead(2);
  trip4 = digitalRead(3);
  trip5 = digitalRead(4);
it is time to look at arrays and fo loops.
« Last Edit: September 01, 2011, 05:25:29 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Guernsey
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Where did Leno go?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So I have. I did see the TX RX labels but didn't think much of it. I'll bear that in mind when it starts getting a bit more complicated and leave those pins free. I could really do with reading more than just Make's 'Getting Started With Arduino' (great book though).

I'll get on the arrays now. Cheers!
Logged

Pages: [1]   Go Up
Jump to: