Download Sample Code HERE!

Grove_Tilt_Switch
Do NOT just copy and paste the code below. Simply click the arrow to download the file.

Related Sample Code

                    
                        // This code assumes you have setup the following:
//    LED Socket Kit to D1
//    Pushbutton to D5
//    Tilt Switch to D7
// NOW, you can either push the button OR have the tilt switch level 
// to turn on the light in the LED Socket.

void setup()
{
    pinMode(1, OUTPUT);
    pinMode(5, INPUT);
    pinMode(7, INPUT);
}

void loop()
{

    if (digitalRead(5)==HIGH)
    {
        digitalWrite(1, HIGH);
        delay(100);
        digitalWrite(1, LOW);
    }

    if (digitalRead(7)==HIGH)
    {
        digitalWrite(1, HIGH);
        delay(200);
        digitalWrite(1, LOW);
    }

}