IFD:Interaktive Elektronik 2012/code

From Medien Wiki

resistive Sensor

Resistive Sensor Steckplatine.png

int mySensorValue;

void setup () {
 Serial.begin(9600);
}

void loop () {
  mySensorValue = analogRead(A0);
  Serial.print("The Sensor Value is: ");
  Serial.println(mySensorValue);
}

switch or Button

Button 1k Pullup Steckplatine.png

int mySensorValue;

void setup () {
 Serial.begin(9600);
 pinMode(13,OUTPUT);
 pinMode(4,INPUT);
}

void loop () {
  mySensorValue = digitalRead(4);
  if (mySensorValue == LOW) {
    Serial.println("The Button is pressed. ");
    digitalWrite(13,HIGH);
  }
  else {
    Serial.println("The Button is not pressed");
    digitalWrite(13,LOW);
  } 
}