Skip to content

Instantly share code, notes, and snippets.

@pvanallen
Last active September 8, 2016 01:21
Show Gist options
  • Save pvanallen/84cf7b8b11933c492b552d34d6dc01fd to your computer and use it in GitHub Desktop.
Save pvanallen/84cf7b8b11933c492b552d34d6dc01fd to your computer and use it in GitHub Desktop.
Creative Tech Course: Arduino Function Example 4
/*
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