Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #30 on: January 01, 2013, 12:24:22 pm » |
i learn alot today/tonight
And that's the beauty of a forum like this.... as long as we do learn!
|
|
|
|
|
Logged
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #31 on: January 01, 2013, 12:27:23 pm » |
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.
|
|
|
|
Malaysia
Offline
Sr. Member
Karma: 7
Posts: 385
|
 |
« Reply #32 on: January 01, 2013, 12:29:05 pm » |
is it true that i read from somewhere that comparison is easier on arduino then using modulo and what not?
|
|
|
|
|
Logged
|
|
|
|
|
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)
|
 |
« Reply #33 on: January 01, 2013, 12:31:36 pm » |
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
Sr. Member
Karma: 7
Posts: 385
|
 |
« Reply #34 on: January 01, 2013, 12:42:52 pm » |
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
Edison Member
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
|
 |
« Reply #35 on: January 01, 2013, 12:51:44 pm » |
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
Sr. Member
Karma: 7
Posts: 385
|
 |
« Reply #36 on: January 01, 2013, 01:02:23 pm » |
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
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #37 on: January 01, 2013, 03:49:50 pm » |
ok guys could you all help me to turn this into a class? heres what i think so far 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#msg1052178John
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Sr. Member
Karma: 7
Posts: 385
|
 |
« Reply #38 on: January 01, 2013, 06:56:26 pm » |
i got the count part working now 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
Sr. Member
Karma: 7
Posts: 385
|
 |
« Reply #39 on: January 01, 2013, 06:59:57 pm » |
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
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #40 on: January 01, 2013, 10:20:03 pm » |
... 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
|
|
|
|
|
Logged
|
|
|
|
|
|