Currently im working in a project were i can select with a knob a number and when i press it the keyboard will type it. The problem is that i dont know if this is even possible, for example If my potentiometer is between 0 and 100 (max is 1023) and i press the button the arduino should type 3. Here is my code, thanks in advance!
#include "Keyboard.h"
const int buttonPin = 4; // input pin for pushbutton
int previousButtonState = HIGH;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
Keyboard.begin();
}
// the loop routine runs over and over again forever:
void loop() {
int buttonState = digitalRead(buttonPin);
int val = analogRead(A0);
Serial.println(val);
delay(1);
if ((buttonState != previousButtonState)
&& (buttonState == HIGH)
&& (val == 0)) {
Keyboard.println("3");
}
if ((buttonState != previousButtonState)
&& (buttonState == HIGH)) {
Keyboard.println("3");
}
}