Skip to content

Instantly share code, notes, and snippets.

@bmidgley
Last active May 27, 2023 18:29
Show Gist options
  • Save bmidgley/616460a99ecb038555ccf6f0ee2d6bc5 to your computer and use it in GitHub Desktop.
Save bmidgley/616460a99ecb038555ccf6f0ee2d6bc5 to your computer and use it in GitHub Desktop.
attiny85 code to print to usb keyboard the analog value at adc1 (p2); also outputs 1 on the GPIO p1 when below 300 (and lighting the LED)
#include "DigiKeyboard.h"
#define ADC1_P2 1
void setup() {
pinMode(1, OUTPUT);
}
void loop() {
char output[32];
int analog;
DigiKeyboard.sendKeyStroke(0);
analog = analogRead(ADC1_P2);
digitalWrite(1, analog < 300 ? HIGH : LOW);
snprintf(output, sizeof(output), "%d\n", analog);
DigiKeyboard.println(output);
DigiKeyboard.delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment