aboutsummaryrefslogtreecommitdiff
path: root/Arduino_STM32-MIDI/examples/Control/IfStatementConditional/IfStatementConditional.ino
blob: 3afeeb174e535d26d6937dc3f42507fb331ae7ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
  Conditionals - If statement

  This example demonstrates the use of if() statements.  It reads the
  state of a potentiometer (an analog input) and turns on an LED only
  if the LED goes above a certain threshold level. It prints the
  analog value regardless of the level.

  The circuit:
  * Potentiometer connected to pin 15.
  Center pin of the potentiometer goes to the Maple pin.
  Side pins of the potentiometer go to +3.3V and ground

  created 17 Jan 2009
  by Tom Igoe

  Ported to the Maple 27 May 2010
  by Bryan Newbold

  http://leaflabs.com/docs/lang/cpp/if.html
*/

// These constants won't change:

const int analogPin = 15;     // Pin that the sensor is attached to

const int threshold = 400;    // A random threshold level that's in
                              // the range of the analog input

void setup() {
	Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
    // Initialize the built-in LED pin as an output:
    pinMode(BOARD_LED_PIN, OUTPUT);

    // Initialize the potentiometer pin as an analog input:
    pinMode(analogPin, INPUT_ANALOG);
}

void loop() {
    // Read the value of the potentiometer:
    int analogValue = analogRead(analogPin);

    // If the analog value is high enough, turn on the LED:
    if (analogValue > threshold) {
        digitalWrite(BOARD_LED_PIN, HIGH);
    }
    else {
        digitalWrite(BOARD_LED_PIN, LOW);
    }

    // Print the analog value:
    Serial.println(analogValue, DEC);
}