Last active
April 7, 2025 10:04
-
-
Save jenschr/3882c9b4946b52203f06b8472bcd0b26 to your computer and use it in GitHub Desktop.
Example showing full range DAC usage on ATtiny412 using megaTinyCore as well as useful PIN numbers
This file contains hidden or 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
/* | |
* In this example, I'm using megaTinyCore with the ATtiny412 Development Board | |
* by Leonerd https://www.tindie.com/products/leonerd/attiny412-development-board/ | |
* | |
* The pins for megaTinyCore and 412 are found in: | |
* /Users/jensa/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.10/variants/txy2/pins_arduino.h | |
* | |
* Useful pins: | |
* Outputs are referenced using "PIN_PA1" | |
* I2C is referenced on PIN_WIRE_SDA (PA1) / PIN_WIRE_SCL (PA2) | |
* SPI is referenced on PIN_SPI_MISO/PIN_SPI_SCK/PIN_SPI_MOSI | |
* Analog pins match their PA number, so PIN_A3 is PA3 is pin 4 | |
* DAC is referenced using DAC_PIN, but output is on PA6 | |
*/ | |
// listing the Arduino pin numbers on physical device | |
#define PA0 5 | |
#define PA1 2 | |
#define PA2 3 | |
#define PA3 4 | |
#define PA6 0 | |
#define PA7 1 | |
void setup() { | |
pinMode(LED_BUILTIN, OUTPUT); | |
// Technically not legal to set DAC reference at 4.3V, | |
// but this produces a full range output? | |
DACReference(INTERNAL4V3); | |
delay(100); | |
analogWrite(PIN_PA6, 255); | |
} | |
void loop() { | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(500); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(500); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment