Last active
September 8, 2016 01:21
-
-
Save pvanallen/84cf7b8b11933c492b552d34d6dc01fd to your computer and use it in GitHub Desktop.
Creative Tech Course: Arduino Function Example 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Arduino Function Example 4 - Range | |
Gets a range from analogWrite - part of a series to experiment with functions | |
Creative Technology Course by Philip van Allen - ArtCenter College of Design | |
*/ | |
const int sensor = A0; | |
int range = 0; | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
Serial.begin(9600); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
range = sensorRange(); | |
Serial.println(range); | |
/* | |
switch(range) { | |
case 0: | |
Serial.println("In range zero"); | |
break; | |
case 1: | |
Serial.println("In range one"); | |
break; | |
case 2: | |
Serial.println("In range two"); | |
break; | |
case 3: | |
Serial.println("In range three"); | |
break; | |
} | |
*/ | |
} | |
int sensorRange() { | |
int sensorValue = analogRead(sensor); | |
sensorValue = map(sensorValue,0,1023,0,3); | |
return sensorValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment