Created
February 24, 2020 13:52
-
-
Save wdevore/cefe300b49f0ee4f5420b20e0fe1de45 to your computer and use it in GitHub Desktop.
Arduino Adafruit Feather-M4 ADC example
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
int sensorPin = A2; // select the input pin for the potentiometer | |
const uint8_t D12 = 12; | |
const uint8_t D11 = 11; | |
const uint8_t D10 = 10; | |
const uint8_t D9 = 9; | |
const uint8_t D6 = 6; | |
const uint8_t D5 = 5; | |
const uint8_t D21 = 21; | |
const uint8_t D22 = 22; | |
void setup() { | |
Serial.begin(115200); | |
pinMode(D12, OUTPUT); | |
pinMode(D11, OUTPUT); | |
pinMode(D10, OUTPUT); | |
pinMode(D9, OUTPUT); | |
pinMode(D6, OUTPUT); | |
pinMode(D5, OUTPUT); | |
pinMode(D21, OUTPUT); | |
pinMode(D22, OUTPUT); | |
} | |
void loop() { | |
int sensorValue = analogRead(sensorPin); | |
Serial.println(sensorValue); | |
delay(100); // Give time for ADC to settle | |
// 120->925 | |
int m = (int)((sensorValue-110) / 104); | |
Serial.print("m: "); | |
Serial.println(m); | |
digitalWrite(D12, LOW); | |
digitalWrite(D11, LOW); | |
digitalWrite(D10, LOW); | |
digitalWrite(D9, LOW); | |
digitalWrite(D6, LOW); | |
digitalWrite(D5, LOW); | |
digitalWrite(D21, LOW); | |
digitalWrite(D22, LOW); | |
// Note: It seems that pins 21 and 22 are miss labled on the feather-m4 | |
// pinout diagram. | |
switch (m) { | |
case 0: digitalWrite(D12, HIGH); break; | |
case 1: digitalWrite(D11, HIGH); break; | |
case 2: digitalWrite(D10, HIGH); break; | |
case 3: digitalWrite(D9, HIGH); break; | |
case 4: digitalWrite(D6, HIGH); break; | |
case 5: digitalWrite(D5, HIGH); break; | |
case 6: digitalWrite(D22, HIGH); break; // The pinout says this should 21 | |
case 7: digitalWrite(D21, HIGH); break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A very simple ADC example.
When you turn the Pot it turns on different LEDs