|
737
|
Using Arduino / LEDs and Multiplexing / Re: Making paterns/sequences(noob question, I bet)
|
on: February 09, 2011, 04:12:17 pm
|
Everyone was a newbie once, no shame in that. Noobs on the other hand never learn, they just keep asking the same question. I hope your are a newbie, not a noob  Well, the first thing you have to understand is that you have a simple byte variable, and the shiftOut() just echoes this variables content's on you 595 outputs. In your code example you have used a constant, like B00000010, instead of a variable. In other words you could have written byte Pattern ; // outside any other function : Pattern = B00000100 ; digitalWrite(latch, LOW); shiftOut(data, clock, MSBFIRST, Pattern); digitalWrite(latch, HIGH); The next thing to focus on is that B00000100 = 4 = 0x4, ie it does not matter what number system you use (binary, decimal, hexadecimal) it is the underlying pattern that shows up. Or, if you say Pattern = 77 ; (and then the shiftOut-stuff) then you see what 77(decimal) is in binary on the LEDs. So, you now can use simply counting //inside the loop(), instead of your code digitalWrite(latch, LOW); shiftOut(data, clock, MSBFIRST, Pattern++); digitalWrite(latch, HIGH); delay(100);
To get your running sequence, you use the fact that a number multiplied by 2 is the same as shifting all bits one step left. Or indeed use the shift function. You have to initialize Pattern to 1 in the setup() ; then replace the Pattern++ with Pattern<<1. Unfortunatly this ony runs through once, so we need to reset it 1 after it the last it is pushed out the left edge, so we add at the bottom if (Pattern==0) Pattern = 1 ;To go the other way use Pattern>>1 and (re)intitalize to B10000000. To go to and fro .... I'll leave you to do the details, but it involves another variable Dir which is 1 or 2 to say if your going left or right, and then use the if (Dir==1) Pattern<<1 and the same the other way, and then to detect when to change the Dir value (when == to B10000000 or == B00000001)
|
|
|
|
|
739
|
Using Arduino / Motors, Mechanics, and Power / Re: PID Example 1
|
on: February 08, 2011, 06:32:03 pm
|
|
+5V ----- Potentiometer----GND | \(the middle leg) ------------Analog 0 That should give you an input voltage on the Analog 0 between 0 and 5V. The analogRead returns a value between 0 and 1023. Use a potentiometer with at least 10K, 100K would be fine.
Yes, The PWM control varies between 0 (0% on) and 255 (100% on)
|
|
|
|
|
742
|
Using Arduino / Sensors / Re: controlling DC motor with encoder
|
on: February 05, 2011, 03:29:37 pm
|
|
Thanks. Nice. Clean, simple and clear.
If you turn the pot QUICKLY it could have >0 on both pwm pins? I suspect it won't happen in this program, the Arduino is too fast, but it is a potential risk (edit:) especially if there is a loose connection to the pot or it is "noisy".
|
|
|
|
|
744
|
Using Arduino / Sensors / Re: controlling DC motor with encoder
|
on: February 05, 2011, 03:18:36 pm
|
|
Hi mechatron, I looked at the link posted by felis and no, it is not interrupt driven, which is explained carefully in the article.
The problem with the code as used in the article is doing such a large Serial.print. There are ways round that, too.
Meanwhile back at your project, I'm just interested; So how much are you able to control the DC motor: Just full whack right/left or have you done speed control, too?
|
|
|
|
|
745
|
Using Arduino / Programming Questions / Re: Do two things at the same time
|
on: February 05, 2011, 03:07:42 pm
|
|
Very briefly, you have two options: Interrupt/event driven programs, or non-blocking polling. For the Arduino I prefer the latter.
Write a couple of routines, checking the state of the switch and RFID, repectivly, and opening the door. No routine may use delay() (or only very short intervals) nor wait for something. This is non-blocking.
Where you need a time-interval in these routines, note the millis() when you "start" your timer, and next time you enter the same routine you see you have a "running timer", and just check if millis() now is less than your interval where you exit, or you do what needed doing.
Your loop() now simply calls all these routines without any timing or logic. The routines can modify global variables, f.ex. "switch is down", which the indvidual routines use to implement the right logic.
I wrote a sketch that did temperature control, two DC motors feed active feedback, and both Serial output and input parsing commands - at the "same time" - using this techinque. The main loop executed 100us at the most, as the routines only do a little each time and never block.
|
|
|
|
|
746
|
Using Arduino / Project Guidance / Re: Thermocouple - continuous stepper speed control
|
on: February 04, 2011, 04:54:01 pm
|
|
3ms is oooodles of time to compute temperature - which I assume is taken an analog reading or two, doing some math -multiply etc, even fancy functions, to map the analog read into a "temperature".
I suspect your worry is keeping the steps. Look at the blink-without-delay example. The same technique enable you to send steps to your motor at intervals determined by the delta to the last millis() og micros(), after having "wasted" a lot of CPU doing the calculation.
The only thing to watch out for is doing Serial output, it will block your loop, unless done in small writes.
|
|
|
|
|
747
|
Community / Website and Forum / Re: FeatureRequest - Mark Interesting Post
|
on: February 04, 2011, 09:39:59 am
|
|
Could you care to give a little more hints what you have (i.e. link) that allows you a - if I understpood you correctly - a local-download(?) of the post. Its little use if the RSS just gives me the whole forum or thread, then I just end up searching again. Its the single posts I am after.
Thank you in anticipation
|
|
|
|
|
748
|
Community / Website and Forum / FeatureRequest - Mark Interesting Post
|
on: February 03, 2011, 05:08:59 pm
|
Hi, I may be asking more of the forum software/database than possible... here is the scenario I sometimes read real good posts explaining /exposing some juicy technical detail. Much later (weeks, months) I have a similar problem, and recall having read about it, but not the details. And then spend ages searching for it  Wouldn't it be nice if I could click on the post (not the topic) and then I can browse/search/list those posts? In fact, if I think about it (ouch!) this is better than Karma as the post recieves the point, but it can then be accredietd to the poster. And the reader is encouraged to only mark posts the reader finds interesting. Edit NB: Adjust topic heading from "Topic" to "Post"
|
|
|
|
|