Patting gesture arduino (with code)

I have added one more expected feature to my cogniglio project, the patting gesture. The original idea was to find a strip of sensor that sensitive to pressure so that when touch it will give some analog input. But instead, I thought of just using my existing sensor which is capasitive sensor. However it is a digital input. So I wrote a code whereby the output will fade to bright the longer input is HIGH and dim back when it is LOW again. Here’s the video.

Here are some codes (for the second video) to give some idea.

int pinIn = 2;
int currentVal = 0;
void setup()
{
//Serial.begin(9600);
pinMode(pinIn,INPUT);
pinMode(9,OUTPUT);
}
void loop()
{
//Patting Module
if (digitalRead(pinIn) == HIGH)
{
fadeIn(5,5);
fadeIn(6,10);
fadeIn(9,15);
fadeIn(10,25);
fadeIn(11,40);
}
//UnPat Module
if (digitalRead(pinIn) == LOW)
{
fadeOut(5,48);
fadeOut(6,30);
fadeOut(9,18);
fadeOut(10,12);
fadeOut(11,6);
}
}
void fadeIn(int pinOut, int delayTime)
{
currentVal = currentVal + 1;
currentVal = constrain (currentVal,0,255);
analogWrite(pinOut,currentVal);
delay (delayTime);
}
void fadeOut(int pinOut, int delayTime)
{
currentVal = currentVal - 1;
currentVal = constrain (currentVal,0,255);
analogWrite(pinOut,currentVal);
delay (delayTime);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: