Last active
June 2, 2021 05:14
-
-
Save cjlawson02/3b8e9a6f25c0cf1d0ff61e18353831a9 to your computer and use it in GitHub Desktop.
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
// the setup routine runs once when you press reset: | |
void setup() { | |
//Set pins 8, 9, 10, and 11 (lower bits of Port B) to output | |
DDRB = 0x3F; | |
//set the reference voltage to match the scale of the input signal | |
analogReference(INTERNAL); | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
// read the input on analog pin 0: | |
int sensorValue = analogRead(A0); | |
// Convert the analog reading (12 bits) to a 6 bit value: | |
int output = (int)(sensorValue * 0.015384); // 63/4095 | |
//output the 6 bit value to the DAC | |
PORTB = output & 0x3F; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment