SODAQ ExpLoRer - Basics

RGB LED

With the first sketch we are going to fade the RED LED of the RGB LED. If you see the RED RGB fade you have installed everything correctly.

Modify the code to understand the code a bit more.
You can use LEDRED, LEDGREEN and LEDBLUE for the colors.
Change the delay(30). 1000 milliseconds is 1 second.
Change the brightness. 0 and 255 are the minimum and maximum.

int led = LED_RED;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

Button

The SODAQ ExpLoRer Rev.5 and higher have a programmable button next to the Bluetooth module.

In this example when we push the button the BLUE LED connected to pin 13 will lit.




void setup() {
  // Configure the button as an input and enable the internal pull-up resistor
  pinMode(BUTTON, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  // Read the button value into a variable
  int sensorVal = digitalRead(BUTTON);

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

Temperature sensor

The SODAQ ExpLoRer has an onboard temperature sensor.

In this example will output every second the temperature in the serial monitor.


#define debugSerial SERIAL_PORT_MONITOR

void setup() {
}

void loop() {
  //10mV per C, 0C is 500mV
  float mVolts = (float)analogRead(TEMP_SENSOR) * 3300.0 / 1023.0;
  float temp = (mVolts - 500.0) / 10.0;

  debugSerial.print(temp);
  debugSerial.println(" C");

  delay(1000);
}