Pages: 1 2 [3]   Go Down
Author Topic: Blink Without delay help again.  (Read 1253 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i learn alot today/tonight

And that's the beauty of a forum like this.... as long as we do learn!
Logged

Retired from Arduino.
PMs are set to ignore all.

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

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

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

ok guys could you all help me to turn this into a class?
heres what i think so far
Code:
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
Logged

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i got the count part working now
Code:
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
Logged

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

* Blinker.ino (1.44 KB - downloaded 2 times.)
Logged

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