Go Down

Topic: Programming traffic light, want multiple loops at random (Read 2531 times) previous topic - next topic


As a civil engineer who started his career in traffic engineering, the idea of a traffic light that changes its phasing randomly, scares the sh!t out of me.....


LOL!! Did I forget to mention that this is a novelty light? I am a mechanic, dabbling in electronics and programming, and these are simply for goofiness, hanging in my shop.


Quote
I would be interested to see the code for your walk/don't walk program.

You left out "/run like hell".


2nd LOL!


Quote
The code compiles fine

All that means is that you have not made an error in syntax. It doesn't mean the code will actually do anything.

Quote
but this is the way the book said to do it.

Sorry I do not believe you. You are misunderstanding what it says.



Hey, I gotta learn somewhere. I have no brilliant friends to help me, (and never even had a home computer until I was 18) so I turn here. You're probably right, so tell me; what is the best way/place/book/anything to learn code by practicing it? Could you instead show me your way, with a breakdown of WHY it works, or point me in a direction more suited to me? I want to learn this...

P.S. Please don't be mad, I know this isn't really a "How To Program" or "Here, Let Us Hold Your Hand" site, I just am kinda lost

UKHeliBob


P.S. Please don't be mad, I know this isn't really a "How To Program" or "Here, Let Us Hold Your Hand" site, I just am kinda lost

I don't think that anyone is mad at you, after all we all started at some time, some have just been doing it longer than others.  I have not been using the Arduino for long so have lots of sympathy for you, but if "the book" really did say this was the way to do it then it was wrong.

A good place to start is with the examples in the Arduino editor File menu.  Have a look a the the Basics/Blink example to see how to set up a pin as an output and turn an LED on and off and you will see where you are going wrong.  Inappropriate use of the delay command as in the example, may cause problems for you later, but one thing at a time.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

johncc



Quote

Quote
but this is the way the book said to do it.

Sorry I do not believe you. You are misunderstanding what it says.



Hey, I gotta learn somewhere. I have no brilliant friends to help me, (and never even had a home computer until I was 18) so I turn here. You're probably right, so tell me; what is the best way/place/book/anything to learn code by practicing it? Could you instead show me your way, with a breakdown of WHY it works, or point me in a direction more suited to me? I want to learn this...


I think Mike was specifically referring to, that he did not believe that the book said to do:
Code: [Select]
ledPin = OUTPUT;
And I agree-- that line of code is very wrong :)

Cheers,
John


Not to argue, but the "blink" example in the Arduino IDE also declares it's led as OUTPUT in pinMode. What did I do wrong again? Why is it not necessary to declare OUTPUTs in my sketch? Please, by all means, re-write mine if you must and show me.

johncc

"Declare as OUTPUT".  Big difference between:
Code: [Select]

  void setup() {
    pinMode( red, OUTPUT);
  }


and what you wrote in http://arduino.cc/forum/index.php/topic,140208.msg1053340.html#msg1053340:

Code: [Select]

  void setup() {
    red = OUTPUT;
    ...
  }


8)

GoForSmoke

You have lots of friends here. We share the same Arduino/electronics hobby/addiction/religion. We want you to get just as hooked.

How long before you'll want to make your own tachometer?

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts


You have lots of friends here. We share the same Arduino/electronics hobby/addiction/religion. We want you to get just as hooked.

How long before you'll want to make your own tachometer?




Honestly? I want to become good enough to build an Arduino and have it "piggyback" off my trucks security system to give such things as rolling the windows up automatically, custom lock/unlock sounds and bump sensors. Until I become versed enough, though, I'm trying to learn to run toys and little robots.

GoForSmoke

Do you want me to admit we're all your enemies and Reptilians to boot? That we're just here to suck you into a living hell of code debugging and burned up parts? To make you lose your friends and have no life at all except what we permit until you're a dried-out husk, and then we laugh at our secret conspiracy meetings? Is that what you want? Well, okay, now you have seen the tip of the evil iceberg!

Just kidding, but hey that was fun.

Be sure to go through the tutorial examples and read threads that look interesting, to pick up on tricks and tips that will help approach future projects. You seem like you can pace yourself which is a valuable anti-burnout/disillusion trait so I think that you will do well indeed.

Some AVR's have CAN interface capability. You can program those on a breadboard using an UNO, the thing is a development board as much as an end-use part. Stand-alone's are much cheaper than whole boards, it's amazing how much you don't need to make one run.

Good Luck, we'll be by to pick you up in the mothership as soon as you've transformed. ;^)
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

arduinohabib

I learned a lot from Getting Started With Arduino by Massimo Banzi, and Arduino Programming Notebook by Brian Evans. Those two books have all the basics.
What is man's best friend? The breadboard!


"Declare as OUTPUT".  Big difference between:
Code: [Select]

  void setup() {
    pinMode( red, OUTPUT);
  }


and what you wrote in http://arduino.cc/forum/index.php/topic,140208.msg1053340.html#msg1053340:

Code: [Select]

  void setup() {
    red = OUTPUT;
    ...
  }


8)


So, to clarify, you DON'T use pinMode to declare input/output. Is that your point? Or do I still not see it?

PaulS

Quote
So, to clarify, you DON'T use pinMode to declare input/output. Is that your point? Or do I still not see it?

Wrong. You do need to use pinMode(). The point was that your code does not, which is why your code doesn't even come close to working.

You should use const in front of all your pin number variables, so that you can NOT make the mistake that is in your code.

AAARRRGGG!!! So, would this be right?!?

Code: [Select]

const int red = 2;
const int yellow = 3;
const int green = 4;
const int yel_arrow = 5;
const int grn_arrow = 6;
const int swap = 4000;
const int time = 7000;
const int redtime = 7000;
const int crosstime = 10;
const int flash = 1000;


void setup(){
  pinMode (red ,OUTPUT);
  pinMode (yellow ,OUTPUT);
  pinMode (red ,OUTPUT);
  pinMode (yel_arrow ,OUTPUT);
  pinMode (grn_arrow ,OUTPUT);
}

PaulS

Quote
So, would this be right?!?

That part is.

Though, some of those values you may want to change while the program is running. If so, remove the const. If not, leave it there. It will prevent you from accidentally changing the value if the value should not be changed.

Yay!! Okay, so, is there a simple way to have multiple light routines? Or do I lack the type-fu? I learn best by starting slow, then learning shortcuts. I also need to know WHY it works, rather than simply having to memorize it, and not knowing if I should use this command or that one.

Go Up