Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Re: Help with millis!!!! on: March 12, 2013, 09:02:32 pm
Don´t know if I´m going in the right direction but I´m into interrupts; if there´s something easier I´d appreciate you let me know. I only need one flag; when that switch actuates, count 5s.
then " do that ".I´m working on it, just need directives, thanks.
2  Using Arduino / Programming Questions / Re: Help with millis!!!! on: March 12, 2013, 05:57:15 pm

Code that has had Tools + Auto Format run on it is easier to read.
Almost sure I did that.
Code that consistently uses { and } after an if statement is easier to understand.
Does this mean that I should ALWAYS use curly braces with IF statements?
I´ve noticed that the code changes if I include or delete them.
How ARE the switches wired?
I´m more comfortable with positive digital electronics; pullup resistors,no problem.
Take a look a FSM's in the playground.
Hope I find it; don´t know what that means.
the code might actually work like that if you moved the "openedtime = millis();  // when did it open"outside of the if and into the else branch. 
Tried that a thousand times.
currenttime will always be just less than openedtime because you are always resetting openedTime.
Is it an error to assign both currenttime and openedtime = millis?
Should I take openedtime outof the main loop? Maybe call a function?
Is setting a flag the only way to solve this?
3  Using Arduino / Programming Questions / Help with millis!!!! on: March 12, 2013, 02:07:40 pm
Hi, everybody. Millis is driving me crazier ( or maybe those curly braces? )
What I´m trying to do is start a timer when a swith comes in, wait a certain time and then " do that ".I googled millis,found tronicstuff, John Boxall and quite a few threads on the forum; can´t understand.
If I change a few things it LED" won´t go ON, or won´t go OFF or go ON immediately.
Just need explanation,not solution; Thanks.
Here´s my code:

int startPin = 2;
int LED1Pin = 3;
int openedPin = 4;
int LED2Pin = 5;
int closedPin = 6;
unsigned long openedtime;  // when did switch go HIGH?
unsigned long opentime;  // time delay
unsigned long currenttime; 

void setup( )
  pinMode ( startPin, INPUT  ); 
  pinMode ( LED1Pin, OUTPUT  ); 
  pinMode ( openedPin, INPUT ); 
  pinMode ( LED2Pin, OUTPUT  );
  pinMode ( closedPin, INPUT );

void loop ( )
  currenttime = millis ( );
  if ( digitalRead ( startPin ) == HIGH )
    digitalWrite ( LED1Pin, HIGH );
  if ( digitalRead ( openedPin ) == HIGH )

    digitalWrite ( LED1Pin, LOW );
    openedtime = millis();  // when did it open
    opentime = currenttime - openedtime;
  if ( (opentime) >= 5000 )
    digitalWrite ( LED2Pin, HIGH );  // turn LED2 ON
    if ( digitalRead ( closedPin ) == HIGH )
      digitalWrite ( LED2Pin, LOW );

4  Using Arduino / Programming Questions / Re: Day/Night LDR sensing code. What is the correct approach to sampling day/night. on: March 10, 2013, 11:07:37 am
Hi, Khilid; I appreciate your sincerity " Simply... You can´t afford me " smiley-grin
5  Using Arduino / Programming Questions / Re: avrdude: stk500_getsync(): not in sync: resp=0x00 on: March 10, 2013, 09:32:06 am
almost every time I get this error it's because I have a fried the IC (atmega 328p)

Hi treebykooba, HOW do you manage this? You are obviously making BAD/WRONG connections. They don´t get fried just by themselves so take some care and save some money.
6  Using Arduino / Programming Questions / Re: avrdude: stk500_getsync(): not in sync: resp=0x00 on: March 09, 2013, 12:26:34 pm
Hi Vikirobot, if your Arduino doesn´t show up under PORTs in device manager, then you most likely didn´t install the drivers correctly.

Unplug your UNO, open PORTS ( COM & LPT ).
When you plug your UNO you should hear the WINDOWS tone, NEW HARDWARE FOUND and you should see your UNO as an USB device.

The WINDOWS installer opens;
Check “ NO “, then NEXT
Check “ LOOK FOR “, check INCLUDE, click “ EXAMINE “
Click on “ drivers “, DON¨T open the folder.
Click on “ drivers “ AGAIN and “ ACCEPT “
Click on  “ NEXT “
WINDOWS will look for, find and install the drivers
Click “ FINISH “and your UNO will show as “ Arduino UNO R3 ( COM X ); X is your port number.

Now open ARDUINO IDE by double clicking on the ICON, select “ TOOLS “,
Verify that your “ BOARD “ is listed as UNO and that your “ SERIAL PORT “ is checked as COM X.
Now you´reready to suffer a bit, but it´s worth the pain.  smiley
7  Using Arduino / Programming Questions / Re: Nested If/Else on: February 20, 2013, 08:43:43 pm
Hi, RF< what they want to say is; write your code so you can see your braces at the beginning of the NEXT line. If you place your cursor just right ( not LEFT of the braces  you´ll see the corresponding RIGHT one ).
If you have 3 left braces in your sketch you HAVE TO have 3 right braces, ALSO.
That´s why you could have “  too MANY right curly braces”  OR  “ too FEW left curly braces “
Count yours and try writing your code like this:

If X
 If Y
      do D
      do C
do B
   do A
8  Using Arduino / Installation & Troubleshooting / Re: Not sure what's wrong.. [solved] on: February 20, 2013, 07:31:02 pm
You DON´T have to but it´s very decent practice; if you´don´t you most likely WILL regret it.
9  Using Arduino / Installation & Troubleshooting / Re: My ORIGINAL UNO r3 got converted to a Mega 1280!!! on: February 20, 2013, 07:24:37 pm
I know WHY and understand the grandchildren part but I CAN´T find a MODIFY button anywhere.
10  Using Arduino / Microcontrollers / Re: Possible to use Arduino without board? on: February 20, 2013, 07:05:32 pm
Once you have uploaded your sketch you can place the uP in another circuit ( EMBED ); as soon as you power the circuit the code starts running.
11  Using Arduino / Programming Questions / Re: While Loop on: February 20, 2013, 02:03:42 am
It  seem s you  want  to control something. Why not try

If (  digitalRead ( sensorval) == HIGH )
digitalWrite ( motorpin , LOW );
digitalWrite  ( motorpin, HIGH );

Never the less, NIck Gammon is expert; post your code.
BTW, take some advice as I was given: go to TOOLS and select AUTOFORMAT, place your parenthesis at the beginning of the next line,
12  Using Arduino / Programming Questions / Re: switches and arduino on: February 20, 2013, 01:23:34 am
Hi;  Hazzarded? Mind smiley, just need a link to read three switches on one pin; I understand the electric circuirt but as I´m new to ARDUINO readAnolog example in reference in vague. Can you help with two switches? leave the other as homework? thanks.
13  Using Arduino / Installation & Troubleshooting / Re: Arduino Uno R3 Windows 7 Serial Port Problem on: February 19, 2013, 11:25:37 am
Hola Enrique; I think you should have at least COM and LPT1. Your UNO r3 doesn´t show up if it´s not connected.  When you plug and unplug it to the USB port you should get an audible indication that something was connected. If the drivers aren´t installed windows should open the NEW HARDWARE detected wizard and allow you to install the drivers.
14  Using Arduino / Installation & Troubleshooting / Re: My ORIGINAL UNO r3 got converted to a Mega 1280!!! on: February 18, 2013, 05:46:31 pm
My son was fooling with MY VERY PRECIOUS ARDUINO! but I have more than enough experience changing ICs, especially fried ones. Thanks, Lefty.
15  Using Arduino / Installation & Troubleshooting / Re: Arduino Uno R3 is an unknown device on: February 18, 2013, 05:40:10 pm
Hi, you´re not the LAST Samurai. Try the following:
Disconnect EVERYTHING from your UNO r3?
Connect it to your PC USB port; You should hear some indication
that Windows detected some hardware and the power LED should turn ON.
If You get a message NEW HARDWARE, reinstall the drivers.
If You had uploaded some sketch the yellow LED might not BLINK,
so don´t worry YET. I use XP; maybe Win7 is a bit different but check
in DEVICE MANAGER your PORTS. You should see “ Arduino UNO R3 ( COMX ) “.
X is the number of the port assigned to your UNO, normally 3.
Open IDE,  or any sketch, click on TOOLS, check  “ BOARD “ as UNO and “ PORT “ as X.
Try uploading BLINK and come back. Ah, the shortest pulse on RESET is long enough.
Pages: [1] 2 3 ... 5