Pages: 1 [2] 3   Go Down
Author Topic: Programming traffic light, want multiple loops at random  (Read 1681 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 90
Posts: 3524
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
ledPin = OUTPUT;
And I agree-- that line of code is very wrong smiley

Cheers,
John

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"Declare as OUTPUT".  Big difference between:
Code:
  void setup() {
    pinMode( red, OUTPUT);
  }

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

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

 smiley-cool
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4036
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

Examples can be found in your IDE.

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4036
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. ;^)
Logged

Examples can be found in your IDE.

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

What is man's best friend? The breadboard!

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"Declare as OUTPUT".  Big difference between:
Code:
  void setup() {
    pinMode( red, OUTPUT);
  }

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

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

 smiley-cool

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46265
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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);
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46265
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2] 3   Go Up
Jump to: