打地鼠

Introduction: 打地鼠

可以訓練小孩反應能力,讓反應不好的人增強能力。

Step 1: 寫程式

int _name ;

void setup(){ // put your setup code here, to run once: pinMode( 2 , OUTPUT); // sets the digital pin as output pinMode( 8 , INPUT); // sets the digital pin as input pinMode( 4 , OUTPUT); // sets the digital pin as output pinMode( 10 , INPUT); // sets the digital pin as input pinMode( 6 , OUTPUT); // sets the digital pin as output pinMode( 12 , INPUT); // sets the digital pin as input _name = random( 1 , 4 ) ;

}

void loop(){ // put your main code here, to run repeatedly: if ( _name == 1 ) { digitalWrite( 2 , HIGH ); // sets the digital pin on/off if (digitalRead( 8 )) { _name = random( 1 , 4 ) ; } } else { digitalWrite( 2 , LOW ); // sets the digital pin on/off } if ( _name == 2 ) { digitalWrite( 4 , HIGH ); // sets the digital pin on/off if (digitalRead( 10 )) { _name = random( 1 , 4 ) ; } } else { digitalWrite( 4 , LOW ); // sets the digital pin on/off } if ( _name == 3 ) { digitalWrite( 6 , HIGH ); // sets the digital pin on/off if (digitalRead( 12 )) { _name = random( 1 , 4 ) ; } } else { digitalWrite( 6 , LOW ); // sets the digital pin on/off } }

Step 2: 接線路

Be the First to Share

    Recommendations

    • Metal Contest

      Metal Contest
    • Halloween Contest

      Halloween Contest
    • Make it Move Challenge

      Make it Move Challenge

    Comments