Hello! I'm new to Arduino and I am creating a Taiko controller as a passion project, so please take it easy on me, thanks!
I've been trying to get this code working on the pro micro for the past day or s0.
The code is taking an analog input from 4 piezo sensor, A0, A1, A2, A3, and converting it to a keyboard input. So for Example, if i were to tap a piezo sensor, based on which of the four, it's supposed to input either an 'a' 'b' 'c' or 'd', not all for at the same time.
For some reason, every time I hit a piezo, it type all 4 letters (abcd), instead of just one or just the other.
Do I have to add other conditions as to make this type just one letter per piezo?
Could anyone tell me if I've done something wrong, it' would be greatly appreciated.
Thanks you all in advance
include <Keyboard.h> const int Sensor0 = A0; const int Sensor1 = A1; const int Sensor2 = A2; const int Sensor3 = A3; const int threshold0 = 100; const int threshold1 = 100; const int threshold2 = 100; const int threshold3 = 100; int val0 = 0; int val1 = 0; int val2 = 0; int val3 = 0;
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
Thank you for your help!
This is the piezo sensor I have used, though i must say i used these on the same project a few year ago, worked well, all that went wrong was isolating the vibrations.
Power to the piezo is being provided by the arduino pro micro which is powered only by a USB connection using a micro USB cable.
Don't know if I can change this as it will be used on PC with an emulator of the rhythm game "Taiko no Tatsujin".
As for the arrangement issue, there is none, as we have also tried testing them one by one, keeping only one connected to the arduino, even so when trying them together we keep them on different surfaces as to avoid one "hearing" the vibration of another.
This is how one of the piezos are connected, with the resistor being 1M Ohm.
Unfortunately, we don't know why we are having so much trouble, and we have encountered several issues such as: random non-stop inputs (even after having messed around with the thresholds and/or without touching them); inputs that don't match the analog in they corrispond to (for example A0 is supposed to input 'a', however it doesn't, it just spam a few letters, and if you press it often enough, it locks up (?), as if you were holding down several keys at once); even just trying to use one (with all the other ones disconnected) ends up typing all 4 inputs, a, b, c, & d, and doesn't stop spamming them.
Sorry for the mess, hopefully I haven't been too annoying, I've tried all i can before asking for help.
Thank you in advance to all who'll respond.
You might be worth putting Serial print statements in your code to see what signal you are getting on the analog inputs.
Remove the keyboard references from your code, for the moment, and just have pure analog input reading and display on your IDE monitor screen.
It might look strange, but the ADC has a capacitor on its input and when the input multiplexer changes input, the must be time for the charge on the capacitor to equal the newer analog input.
Reading each input twice gives the capacitor a chance to keep up.
Hey, it worked for 20 seconds or so, though only the 'a' & 'c' inputs, then it went back to writing random inputs.
But it did work, even if just for a little bit.
Any tips on how to keep the code from having a stroke?
Hi,
You need to write some code that JUST reads the inputs and displays them on the IDE serial monitor, establish that you are receiving valid values.
Forget about all the if statements and keyboard statements.
Here are a few values while touching and applying pressure to the piezo.
As you can see the values stay around 300 even when not touching it, and don't change even while touching it. New Text Document (3).txt (653 Bytes)
UPDATE: apparently, when adding the serial print in, in the code with the if statements, the piezos stop working, without it, it sometimes work other times it inputs random gibberish.
UPDATE#2: nevermind, stopped working and just spamming 'a's now.