3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Making an interactive twinkling winter cap

Step 4More code, for use with a mechanical tils sensor

More code, for use with a mechanical tils sensor
The first code was just a running pattern around the available LED's.

This links provides another interactive pattern of the LED's, using a metal ball in a square casing.
See the grey box next to the atmega328. It was salvaged from a deceased Sony dog!

Using this tilt sensor, I had to make a tiltcheck function. This seemed easy, but it was not!
The principle was right, but a delay had to be inserted switching the PIN pattern.

See the function in the script:
uint8_t checkTilt(){

uint8_t tiltPin = 0;
PORTC |=(1<<PC1);
PORTC |=(1<<PC5);
uint8_t delayTime = 50;//--------------------------> delay
PORTC &= ~_BV(PC1);
_delay_ms(delayTime);//--------------------------> delay
if ( (PINC & ( 1<<PC4)) == 0 ) tiltPin = 2;//left
if ( (PINC & ( 1<<PC2)) == 0 ) tiltPin = 1;// front
PORTC |=(1<<PC1);
_delay_ms(2*delayTime);//here a delay is necessary, otherwise readings are strange ???
PORTC &= ~_BV(PC5);
_delay_ms(delayTime);//--------------------------> delay
if ( (PINC & ( 1<<PC4)) == 0 ) tiltPin = 5;//back
if ( (PINC & ( 1<<PC2)) == 0 ) tiltPin = 3;// right
if ( (PINC & ( 1<<PC3)) == 0 ) tiltPin = 4;//mid -> top

PORTC |=(1<<PC5);
return tiltPin;
}

http://www.contrechoc.com/instructables/twinkle_winter_cap_project_2.zip

Now when you move your head, the LED's will change pattern to left, right, fron or back. And when not inclined the top LED's are on.



« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
14
Followers
17
Author:contrechoc
also doing some blogging here: http://myfablab.wordpress.com/