got rotary phone and computer talking. numbers are working great. now how do make a passcode THIS IS DRIVING ME NUTS!!!!!! very new to arduino could really use some guidance
thanks in advance......
The problem is in the code you didn't post.
OK, now wrap
[code] and [/code]
around your code so that the forum software doesn't misinterpret it.
Ok, thanks for info. New to this. You can probably tell!
To post code and/or error messages:
- Use CTRL-T in the Arduino IDE to autoformat your code.
- Paste the autoformatted code between code tags (the </> button)
so that we can easily see and deal with your code. - Paste the complete error message between code tags (the </> button)
so that we can easily see and deal with your messages.
Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.
If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a photograph of the wiring.
Good Luck!
You should see "quick edit" near the bottom-right of your own posts.
The best way to do this might be to look at all the passcode examples online which use a keypad. They often seem to have a function which waits for the next key to be pressed and returns the value of that key. Try to wrap your rotary code into a rotary() function that just returns the number. Then paste it into a keypad example and change every keypad.getKey() into rotary().
The posted code does not compile. At the very least, it is missing
}
at the end.
i think that }was the only problem. not looking for the code to be checked. just looking for a way to make a pass/code. if you know a way to do this that would be greatly appreciated.
int needToPrint = 0;
int count;
int in = 2;
int lastState = LOW;
int trueState = LOW;
long lastStateChangeTime = 0;
int cleared = 0;
int code = 789;
int relay = 7;
// constants
int dialHasFinishedRotatingAfterMs = 100;
int debounceDelay = 10;
void setup()
{
Serial.begin(9600);
pinMode(in, INPUT);
pinMode(relay, OUTPUT);
}
void loop()
{
int reading = digitalRead(in);
if ((millis() - lastStateChangeTime) > dialHasFinishedRotatingAfterMs) {
// the dial isn't being dialed, or has just finished being dialed.
if (needToPrint) {
// if it's only just finished being dialed, we need to send the number down the serial
// line and reset the count. We mod the count by 10 because '0' will send 10 pulses.
Serial.print(count % 10, DEC);
needToPrint = 0;
count = 0;
cleared = 0;
}
}
if (reading != lastState) {
lastStateChangeTime = millis();
}
if ((millis() - lastStateChangeTime) > debounceDelay) {
// debounce - this happens once it's stablized
if (reading != trueState) {
// this means that the switch has either just gone from closed->open or vice versa.
trueState = reading;
if (trueState == HIGH) {
// increment the count of pulses if it's gone high.
count++;
needToPrint = 1; // we'll need to print this number (once the dial has finished rotating)
}
}
lastState = reading;
}
}
//now i'm wondering if i can use the int.count
// use another int. call it passCode = 789
// if passcode=count
//turn on relay
//or something of this nature
vaj4088:
The posted code does not compile. At the very least, it is missing}
at the end.
I'm sorry but up to post #8, WHAT code?
Tom.....
Or has a post with the code been REMOVED?
Yes, an entire post has been deleted. (Maybe more than one?)
Spacewhistle2, did you try looking at the keypad examples?
Your code in reply #8 looks the same as what I remember from earlier. Have you had any opportunity to try to extract the core of it into a function?