Step 4More code, for use with a mechanical tils sensor
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 Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|











































