Time/clock - based actions with Arduino

Thread Starter

wayneh

Joined Sep 9, 2010
17,496
Complete noob here. I've just received an Arduino Uno R3 as a gift and I've managed to get the IDE running, and to flash and dim an LED. (Woohoo!)

But now I'd like to throb the LED with a sine wave. When I've done this in other languages, I accessed the system time (x) and calculated the appropriate brightness level (y) from that time. How can I do that with the Arduino? Is there an on-board clock or timer that can be accessed? I could increment a counter that advances with each loop iteration and use that as a proxy for time, but it's kludgy and not exactly the same.
 

Thread Starter

wayneh

Joined Sep 9, 2010
17,496
Here's another noob-ish question. In the dark last night I noticed that the onboard LED at pin 13 is throbbing along with the analog pins 9, 10, and 11 that I have an RGB LED connected to.

My first thought was code running from a previous project, the Blink code you run first thing. But it's not blinking, it's throbbing. And this morning in the daylight I notice that it's quite dim even at its brightest.

It looks like a little current from pin 11 is leaking through the LED at pin 13. Is that possible? Does anyone else's Uno behave this way?

[UPDATE] I can make the faint LED light go dark by setting the "digitalWrite(LED_BUILTIN, LOW);".

[UPDATE2] Just initializing the pin without ever writing to it also stops the faint glow: "pinMode(LED_BUILTIN, OUTPUT);"
 
Last edited:

dl324

Joined Mar 30, 2015
16,839
LED at pin 13 is throbbing along with the analog pins 9, 10, and 11 that I have an RGB LED connected to.
Pins 9, 10, and 11 aren't analog. What do your pin names/numbers mean WRT to the official designations? The numbers in gray boxes are physical pin numbers.
clipimage.jpg


Most refer to the digital pins as D0-13 and analog A0-5.

EDIT: It would appear that 13 refers to D13:
clipimage.jpg
 

djsfantasi

Joined Apr 11, 2010
9,156
Perfect! That's what I needed, the syntax reference instead of just the answer. I now have my RGB LED throbbing the 3 colors 120° apart in phase. Cute little device.
I have bookmarked the reference page. It contains syntax and use of all the Arduino C commands.
 
Last edited:

ApacheKid

Joined Jan 12, 2015
1,533
Complete noob here. I've just received an Arduino Uno R3 as a gift and I've managed to get the IDE running, and to flash and dim an LED. (Woohoo!)

But now I'd like to throb the LED with a sine wave. When I've done this in other languages, I accessed the system time (x) and calculated the appropriate brightness level (y) from that time. How can I do that with the Arduino? Is there an on-board clock or timer that can be accessed? I could increment a counter that advances with each loop iteration and use that as a proxy for time, but it's kludgy and not exactly the same.
I did exactly this a while back but for the STM32.

I use DMA to pump values into the DAC and then was able to see the sine signal on a scope. It was really just a technical exercise to prove how to do this, it took a few weeks to get it working and 99% of that was logistical dealing with the specifics of the device I was using and understanding the semantics of DMA.

Because it was like 9 months ago I've promptly forgotten everything I'd learned about DMA on STM32 - such is life.

Still the code may be of some value to you, its for the Nucleo-F446RE and is built using MS Visual Studio coupled with Visual GDB.

The sine table stuff is here.
 
Last edited:

Thread Starter

wayneh

Joined Sep 9, 2010
17,496
The sine table stuff is here.
Thanks, but I'm just goofing around and dipping my toe in the Arduino waters so far. Playing with LEDs is always a good way to start, because of the feedback, and yeah, they're almost cool. The Arduino supports trig functions, so I calculate on the fly without worrying about a table.

I mentioned the Arduino to the wife today and she asked, "What's it for, what does it do?" I had a hard time coming up with a wife-appropriate answer. It's like trying to explain why the Three Stooges were funny. You either get it or you don't.
 
Top