Examples - Electronic Bricks - Electronic Brick Magnetic Switch
Digital-In, Using the Electronik Brick Magnetic Switch.
This program gives you a basic understanding how to use the Magnetic Switch Brick.
The Arduino can Read the Digital signal via the the digital pins, and put
out the digital signal through the same pins. In Arduino there are 14 digital pins, from
0-13.
Hardware Setup:
/* Magnetism LED switch Example: Digital input and output / interaction Put a megnet close to the Magnetism brick and turn the led light on */ int Magnetism = 9; //define the 9th digital pin for magnetism brick int LED = 8; //define the 8th digital pin for LED brick void setup() { pinMode(LED,OUTPUT); //set the LED pin for digital output pinMode(Magnetism,INPUT); //set the Magnetism pin for digital input } void loop() { if (digitalRead(Magnetism)) // if button press digitalWrite(LED,HIGH); // light the LED else // if not press digitalWrite(LED,LOW); // turn off the LED }