Bukit Mertajam, Penang

Pinguino + Input Shield

Pin:

Pin Allocation:

Example: LED display using analog and digital button

Flow Chart:

Program Code:
#define x 15
#define y 14
#define button_A 5
#define button_B 3
#define button_C 4

#define LED_TOP 24
#define LED_BOTTOM 22
#define LED_RIGHT 25
#define LED_LEFT 23
#define LED_A 26
#define LED_B 27
#define LED_C 28

void setup()
{
    int i;
    for(i=3;i<=5;i++)
    pinMode(i, INPUT);
    for(i=22;i<=28;i++)
    pinMode(i,OUTPUT);
}

void loop()
{
    int valx,valy;
    int i;

    while(1)
    {
		digitalWrite(LED_LEFT, LOW);
		digitalWrite(LED_RIGHT, LOW);
		digitalWrite(LED_BOTTOM, LOW);
		digitalWrite(LED_TOP, LOW);
		digitalWrite(LED_A,LOW);
		digitalWrite(LED_B,LOW);
		digitalWrite(LED_C,LOW);

		valx=analogRead(x); //Read Analog input
		if(valx>1000)
		digitalWrite(LED_LEFT, HIGH);
		else if(valx<20)
		digitalWrite(LED_RIGHT,HIGH);

		valy=analogRead(y);
		if(valy>1000)
		digitalWrite(LED_BOTTOM, HIGH);
		else if(valy<20)
		digitalWrite(LED_TOP,HIGH);

		if(digitalRead(button_A)==0)    //Check Button A
		digitalWrite(LED_A, HIGH);   // Set LED on

		else if(digitalRead(button_B)==0)   //Check Button B
		digitalWrite(LED_B, HIGH);    // Set LED Off

		else if(digitalRead(button_C)==0)   //Check Button C
		digitalWrite(LED_C, HIGH);    // Set LED off

    }
}

Demonstration:
[youtube]http://www.youtube.com/watch?v=gOj-vQolYfk[/youtube]

Buy

[vc_cta h2=”” style=”outline” color=”white” add_button=”left” btn_title=”Input Shield V2″ btn_color=”orange” btn_i_icon_fontawesome=”fa fa-opencart” btn_css_animation=”appear” css_animation=”appear” btn_link=”url:http%3A%2F%2Fwww.cytron.com.my%2Fp-shield-input2||” btn_add_icon=”true”][/vc_cta]

Related Posts

Leave a comment

Get 7 Tips for Developing Electronic Projects
We respect your privacy.
Loading...