Skip to content

Button

The SODAQ ONE V1 and V2 have a programmable button.
The sketch will turn on the green LED when the button is pushed down.

Note

The SODAQ ONE V3 doesn't have a programmable button onboard.

void setup() {
  // Start serial connection
  SerialUSB.begin(9600);
  // Configure the button as an input and enable the internal pull-up resistor
  pinMode(BUTTON, INPUT_PULLUP);
  pinMode(LED_GREEN, OUTPUT);
}

void loop() {
  // Read the button value into a variable
  int sensorVal = digitalRead(BUTTON);
  // Print out the value of the button
  SerialUSB.println(sensorVal);

  // Turn on the LED when the Button is pushed
  if (sensorVal == HIGH) {
    digitalWrite(LED_GREEN, HIGH);
  } else {
    digitalWrite(LED_GREEN, LOW);
  }
}

Questions

You can ask us anything on our Forum.