Go Down

Topic: Blink Without delay help again. (Read 1 time) previous topic - next topic

JimboZA


i learn alot today/tonight


And that's the beauty of a forum like this.... as long as we do learn!
My hovercraft is full of eels.

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

AWOL

Quote
is this something that you meant?
Yes, but not so complicated.
"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.

ash901226

is it true that i read from somewhere that comparison is easier on arduino then using modulo and what not?

tuxduino

Forget code optimizations. Write code that works and is readable / maintainable. That's the first form of optimization. Low level optimization is better left off to the compiler.

ash901226

i guess your rite tuxduino,
actually the real reason for me to make the blink without delay with variable on off time is so that i could make my own code to control a 6 axis Mill. i know big ambition rite. but hay its like what they say in my langguage " Impikan langgit supaya bila jatuh dapat awan" its something like hope for the sky if you fall your atleast in the clouds if im not mistaken. my stepper motor controller is using Step/direction control. i have try countless of library. in my opinions all have its pros and cons. but i know that maybe i could give it a try who knows maybe i can make my own controller, well if i fail atleast i will have learn alot i know some of you thinking while reading this why invent the wheel again and again. just couse i want to learn and nothing more.

tuxduino

Reinventing the wheel is one (good) way to learn, everyone has done that, at least once.
When tackling a bigger project, though, it's far better to learn how to use others' wheels. That is, libraries. When you put together buttons, blinking leds, stepper motors and some sensors, you'll go nowhere without libraries.

ash901226

well i hope so, so now my problem is how to make it count the number of on it have done.

johncc


ok guys could you all help me to turn this into a class?
heres what i think so far
Code: [Select]

class Blink
...


would this be correct ? it does compile but im lost when i get to this part.


Hi Ash, did you not see my reply to your post in "Arduino Class C++"?
http://arduino.cc/forum/index.php/topic,139996.msg1052178.html#msg1052178

John

ash901226

i got the count part working now
Code: [Select]

unsigned long OFF_TIME=1000;
unsigned long ON_TIME=100;

const int ledPin =  53;
int ledState = LOW;
long previousMillis = 0;
int Count=0;
unsigned long interval;

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

void loop()
{
 if (Count<=10)
 {
   unsigned long currentMillis = millis();

   if(currentMillis - previousMillis > interval) {
     // save the last time you blinked the LED
     previousMillis = currentMillis;  

     // if the LED is off turn it on and vice-versa:
     if (ledState == LOW) {
       ledState = HIGH;
       interval = ON_TIME;
       Count++;
     }
     else
     {
       ledState = LOW;
       interval = OFF_TIME;
     }
     digitalWrite(ledPin,ledState);
   }
 }
 else
 {
   digitalWrite(ledPin,LOW);
 }
}


now would be a great time to start varying the off time

ash901226

don't get me wrong johncc, i saw your answer at it work great but i saw a fetal flaw in using switch statement that's why i turn it into a if statement program. Btw thanks it works great and you know what i had been turning Steppers using your program.

johncc


...
The constructor will be called before the init() function is called. It is the init() function that sets up the hardware, so calling pinMode() before init() is a waste of time.
...


I thought of that but found that pinMode() was effective.  This was on a Teensy 2 btw,  so I'm not sure if its the same on an Uno, etc.

I suppose it's "undefined" or uncertain whether it should/could/would work or not, so I agree a separate setup() method is best.

Cheers,
John

Go Up