0
Offline
Newbie
Karma: 0
Posts: 18
Arduino rocks
|
 |
« on: October 29, 2009, 05:36:12 am » |
Hello everyone. I tried to do this on a workshop and it worked great: http://little-scale.blogspot.com/2009/04/how-to-use-arduino-to-generate-glitchy.htmlAnd this is our result (with VGA splitter, keep in mind): However, I couldn't find out what the arduino was doing exactly. This is the code it was running: void setup() { DDRD = B11111111; }
void loop() { PORTD = analogRead(0); } Is this true C? Or assembler or something? Can anyone explain it to me or give me some links for research?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 94
Arduino rocks
|
 |
« Reply #1 on: October 29, 2009, 06:25:09 am » |
The code is very simple, first of all: DDRD = B11111111; Sets PORT D to be all outputs, with DDRD being the Port D Data Direction Register. See: http://www.arduino.cc/en/Reference/PortManipulationNext: PORTD = analogRead(0); This reads the value from Analog pin 0 and converts it to a digital value, and then outputs it to Port D (which will be sent to the monitor) See: http://www.arduino.cc/en/Reference/AnalogRead
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #2 on: October 29, 2009, 09:51:26 am » |
PORTD = analogRead(0); So analogRead returns a unsigned int of 10 bits, what bits end up in the 8 bit PORTD register? Wouldn't one have to scale or map the 10 bit value to a 8 bit value before sending it out an 8 bit port? Lefty
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 18
Arduino rocks
|
 |
« Reply #3 on: October 29, 2009, 09:51:46 am » |
Thanks. I'll have a look into it.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 18
Arduino rocks
|
 |
« Reply #4 on: October 29, 2009, 09:56:35 am » |
@retrolefty, I think it just takes the last 8 bits of the 10 bit analog in.
That's at least what the original programmer states on the website.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #5 on: October 29, 2009, 10:04:04 am » |
I think it just takes the last 8 bits of the 10 bit analog in.
Last 8 bits meaning bits 0-7 of the int or bits 8-15 of the int? either is kind of useless as what I think one would want is to transfer the 8 most significant bits on the 10 bit A/D value (bits 2 to 9 of the returned int) into bits 0 to 7 of PORTD? I don't think the standard C casting rules will do that? Lefty
|
|
|
|
« Last Edit: October 29, 2009, 10:06:09 am by retrolefty »
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 94
Arduino rocks
|
 |
« Reply #6 on: October 29, 2009, 10:36:32 am » |
either is kind of useless I don't think it matters for the particular application it's being used for, which is essentially just showing random bars of colour on the screen, which change frequently. It gives a random-ish output, which is all they want, so the fact that some bits are being lost isn't a problem.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #7 on: October 29, 2009, 12:02:15 pm » |
I don't think it matters for the particular application After looking at the posted videos I can see what you mean, just cause changes and in that case it probably accomblish the desired effect. Still I think it may be a bad example and not a good programming example. C casting rules are hard enough to understand and master to have examples like this to try and learn from.  Lefty
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 2
Arduino rocks
|
 |
« Reply #8 on: November 27, 2009, 07:26:12 pm » |
hello! i've been trying the same thing using little scales former blog entry: http://little-scale.blogspot.com/2008/02/hacking-vga-lines-with-arduino.htmland its overall documentation photo can't make everything out in detail on the picture (and i'm unsure with the diagram), therefore: arduino digital pin -> right POT terminal (?) female VGA pin -> middle POT terminal (?) arduino ground -> left POT terminal (here i'm confused, for arduino duemilanove has exactly 3 GND pins (plain luck?!) - and in this case they seem to "leave" the POT to some place else) cheers in advance..! -jonas
|
|
|
|
« Last Edit: November 28, 2009, 03:51:20 am by flim »
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #9 on: November 27, 2009, 08:35:52 pm » |
(here i'm confused, for arduino duemilanove has exactly 3 GND pins (just luck?!) You can edit your post now and put a real link in, 1st post can't as a spam filter. I can answer this one. You can use any of the Arduino ground pins, they are all the same. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 2
Arduino rocks
|
 |
« Reply #10 on: November 28, 2009, 04:06:34 am » |
hej lefty!
thanks for your help. it's just, that the background of the photo gets a bit blurry.
i'm not that familiar with breadboards yet. little scale seems to connect the left terminal from the poti to the bus strip. but i can't make out any connection between this bus strip and the arduino ground pin(s).
can anybody help me out? (too bad i don't have a bird's eye view on this one...)
cheers!
-jonas
|
|
|
|
|
Logged
|
|
|
|
|
|