ALL SECURITY RELATED TOPICS ON IoT wILL BE POSTED THERE
>> ARDUINO - MY FIRST CUSTOM HACK
After tinkering around with the arduino starter kit; I simply had to
extend some of the examples and mix and match them to create something
unique just for fun. In this case, I took one example using six LEDs
and another using the piezo element to create an audibly annoying but
visually satisfying hack.
Once you have played with all the samples in the arduino starter kit
it should be obvious what changes I made - simply connect six red LED
and the piezo elements to the digital connections of the arduino uno.
The LEDs are then connected to the ground lines using 220Ω resistors
- should be simple figure out based on the other examples provided.
The sketch code is below:
// simple arduino sketch using six LED's and the piezo element
// - design is to have a sequence 0,1,2,3,4,5,5,4,3,2,1,0 repeat
// - NOTE: double use of LEDs 0 and 5 - this is for nice visual effect
#define ledPINBase 2
#define ledPINCount 6 // pins 2,3,4,5,6 and 7
#define piezoPIN 8
// we want to move across the LED pins in approximately a second
#define delayPeriod (1000 / ledPINCount)
// we want to play tones an octive up and down from middle C
#define toneBase 262
#define toneDiff ((toneBase * 2) / ledPINCount)
#define toneDuration (delayPeriod / 2)
// some global variables
int g_direction = 1;
int g_led = ledPINBase;
// configuration of the arduino
// configure the LED pins - turn them all off
for (int i=ledPINBase; i<(ledPINBase+ledPINCount); i++)
// called periodically by the arduino core - this is where we do stuffvoid loop()
// for visual effect; toggle the state of the LED
state = digitalRead(g_led);
if (state == HIGH) digitalWrite(g_led, LOW);
else digitalWrite(g_led, HIGH);
// iterate forwards through LEDs
if (g_direction == 1)
// have we had a led counter overflow?
if (g_led == (ledPINBase+ledPINCount))
g_led == (ledPINBase+ledPINCount)-1;
g_direction = -1;
// iterate backwards through LEDs
// have we had a led counter underflow
if (g_led == (ledPINBase-1))
g_led = ledPINBase;
g_direction = 1;
// play a ticking sound
tone(piezoPIN, toneBase + ((g_led-ledPINBase)*toneDiff), toneDuration);
// wait a specific period of time before the next iteration
The arduino IDE is extremely simple to use - the "scratchpad" is where you
simply write some C++ code and you can verify and deploy to the device when
it is connected via USB cable. While the size of arduino applications seems
to be limited to 32,256 bytes (assuming, 32kb not including the bootstrap)
you can still do a lot with the device once you figure out how to hook up
the sensors and components to the breadboard.
I think I will have more fun on these boards once the LCD (240x320) and
Gameduino shields I ordered the other day turn up - there is this crazy
satisfaction about receiving a small package in the mail and getting that
warm fuzzy feeling like it is xmas every day with gadget madness. Must
be the inner geek in me screaming to come out!
I implemented a small binary clock using the exact arduino configuration.
All content provided on this blog is for informational purposes only.
All comments are generated by users and moderated for inappropriateness periodically.
The owner will not be liable for any losses, injuries, or damages from
the display or use of this information.