Hi
I have a project that involves four thumbwheel switches, to control the frequenzy to shut and poen a pair of old 3D glasses that is basically two large one-pixel LCD screens.
this setup will take the numbers (RPM) entered on the thumbwheels and divide it by 60 (seconds) to send the frequnezy (RPM/60) to the glasses, so that I can look at rotating parts as if they are standing still... or figure out the RPMs by adjusting the tumblewheels until the rotating stuff is standing still.
problem is that the thumbwheels PDF! is a decimal type (what i had in my parts-bin) and each switch has outputs for 0-9 and a common.
the question is, how do I connect them.
I have a couple of ideas,
1: setting them up with one outout for each of the wheels, and 10 inputs, and let the arduino scan the switches.
this method needs 14 IO-pins, so there is no pins avaliable for the rest.
2: Shift registers, needs 40 inputs / 8 inputs on each register = 5 chips
3: a combination of 1 and 2.
connecting the common on each of the switches to a analog input, and a cascade of diodes to reduce the voltage to each number on the switch, so that, 9=5V, 8=4,4V, 7=3,8v etc. and connect 0 to gnd
and somehow decode the analog signal to numbers in arduino.
Lots of digital pins so no problem with directly inputing several decade switches. I would wire the common of each switch to ground and enable the internal pull-up resistors on the digital input pins used. Your sketch would read input pins and look for a low to determine the active switch position.
I used my initial idea with cascading diodes and using 4 analog inputs (my first adventure in analog)
and i read the value perfectly
now I have to find a way to use the input, for now i just send the value over the serial port so that i can read it in the serial monitor.
Code:
int potPin0 = 0; // select the input pin for the potentiometer
int potPin1 = 1;
int potPin2 = 2;
int potPin3 = 3;
int val0 = 0; // variable to store the value coming from the sensor
int val1 = 0;
int val2 = 0;
int val3 = 0;
void setup() {
Serial.begin(9600); // use the serial port to send the values back to the computer
}
void loop() {
val0 = analogRead(potPin0); // read the value from the sensor
if (val0 < 2) Serial.print('0');
else if (val0 < 100) Serial.print('1');
else if (val0 < 200) Serial.print('2');
else if (val0 < 300) Serial.print('3');
else if (val0 < 400) Serial.print('4');
else if (val0 < 600) Serial.print('5');
else if (val0 < 700) Serial.print('6');
else if (val0 < 800) Serial.print('7');
else if (val0 < 950) Serial.print('8');
else if (val0 > 1000) Serial.print('9');
val1 = analogRead(potPin1); // read the value from the sensor
if (val1 < 2) Serial.print('0');
else if (val1 < 100) Serial.print('1');
else if (val1 < 200) Serial.print('2');
else if (val1 < 300) Serial.print('3');
else if (val1 < 400) Serial.print('4');
else if (val1 < 600) Serial.print('5');
else if (val1 < 700) Serial.print('6');
else if (val1 < 800) Serial.print('7');
else if (val1 < 950) Serial.print('8');
else if (val1 > 1000) Serial.print('9');
val2 = analogRead(potPin2); // read the value from the sensor
if (val2 < 2) Serial.print('0');
else if (val2 < 100) Serial.print('1');
else if (val2 < 200) Serial.print('2');
else if (val2 < 300) Serial.print('3');
else if (val2 < 400) Serial.print('4');
else if (val2 < 600) Serial.print('5');
else if (val2 < 700) Serial.print('6');
else if (val2 < 800) Serial.print('7');
else if (val2 < 950) Serial.print('8');
else if (val2 > 1000) Serial.print('9');
val3 = analogRead(potPin3); // read the value from the sensor
if (val3 < 2) Serial.print('0');
else if (val3 < 100) Serial.print('1');
else if (val3 < 200) Serial.print('2');
else if (val3 < 300) Serial.print('3');
else if (val3 < 400) Serial.print('4');
else if (val3 < 600) Serial.print('5');
else if (val3 < 700) Serial.print('6');
else if (val3 < 800) Serial.print('7');
else if (val3 < 950) Serial.print('8');
else if (val3 > 1000) Serial.print('9');
Serial.print(" RPM. ");
delay(1000);
}
Pics:
as you can see, only 4 analog pins in use
and a printscreen, showing the same result in the serial monitor as on the thumbwheels :
Ok, so Ive been away from this project for a while now, and I need help with the next part.
I've changed my code a little now so it adds the numbers together and sends one 4-digit number, instead of 4 seperate numbers without space between them over serial, and I added some math to devide the 4-digit input by 60, to get Hz/RPS instead of RPM
the next obsticle is to output this frequenzy to pin 13
Here is some code:
#include "math.h"
int potPin0 = 0; // select the input pin for the potentiometer
int potPin1 = 1;
int potPin2 = 2;
int potPin3 = 3;
int val0 = 0; // variable to store the value coming from the sensor
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
int val7 = 0;
int setting;
int Hz;
int ledPin = 13;
void setup() {
Serial.begin(9600); // use the serial port to send the values back to the computer
}
void loop() {
val0 = analogRead(potPin0); // read the value from the sensor
if (val0 < 2) val4 = 0;
else if (val0 < 100) val4 = 1000;
else if (val0 < 200) val4 = 2000;
else if (val0 < 300) val4 = 3000;
else if (val0 < 400) val4 = 4000;
else if (val0 < 600) val4 = 5000;
else if (val0 < 700) val4 = 6000;
else if (val0 < 800) val4 = 7000;
else if (val0 < 950) val4 = 8000;
else if (val0 > 1000) val4 = 9000;
val1 = analogRead(potPin1); // read the value from the sensor
if (val1 < 2) val5 = 0;
else if (val1 < 100) val5 = 100;
else if (val1 < 200) val5 = 200;
else if (val1 < 300) val5 = 300;
else if (val1 < 400) val5 = 400;
else if (val1 < 600) val5 = 500;
else if (val1 < 700) val5 = 600;
else if (val1 < 800) val5 = 700;
else if (val1 < 950) val5 = 800;
else if (val1 > 1000) val5 = 900;
val2 = analogRead(potPin2); // read the value from the sensor
if (val2 < 2) val6 = 0;
else if (val2 < 100) val6 = 10;
else if (val2 < 200) val6 = 20;
else if (val2 < 300) val6 = 30;
else if (val2 < 400) val6 = 40;
else if (val2 < 600) val6 = 50;
else if (val2 < 700) val6 = 60;
else if (val2 < 800) val6 = 70;
else if (val2 < 950) val6 = 80;
else if (val2 > 1000) val6 = 90;
val3 = analogRead(potPin3); // read the value from the sensor
if (val3 < 2) val7 = 0;
else if (val3 < 100) val7 = 1;
else if (val3 < 200) val7 = 2;
else if (val3 < 300) val7 = 3;
else if (val3 < 400) val7 = 4;
else if (val3 < 600) val7 = 5;
else if (val3 < 700) val7 = 6;
else if (val3 < 800) val7 = 7;
else if (val3 < 950) val7 = 8;
else if (val3 > 1000) val7 = 9;
setting = val4 + val5 + val6 + val7;
Hz = setting / 60;
digitalWrite(ledPin, HIGH); // set the LED on
delay(time); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(time); // wait for a second
}
Help will be rewared with a biscuit, or atleast a picture of one, as it is illegal to ship food internationally..
Who knows.. All I know is that the postal service lists food along with firearms, explosives, medicine and some other stuff as goods thats not allowed for shipping out of the country..
I added a few lines more code, and hooked up my Fluke Scopemeter to the output-pin, and I have adjustable frequency out, it not 100% accurate, but not totally off. when I selected 3000 rpm, i should get 50Hz (50HZ X 60sec = 3000 RPM) But I got 46 Hz instead (2760 rpm).
and at 6000 rpm I should get 100Hz, but got 89 instead...
small issues, hopefully resolvable..
Hi, I'm a newby that is trying to do a similar thing with an array of thumbwheel switches. Each switch has a common and then four "bits" that encode the 0-9 position.
Could someone please help explain the diode circuit and how the voltage drop works? i.e. how are the diodes are connected to provide unique voltages for each position? This is a clever solution, if only I could understand it!