DangerToMyself:
I think you mean 100 ohm resistor. Not 100k ohm. If 100k, THAT would be your problem. You would also benefit by posting your code. Just be sure to use the forum's code tagsso it looks like this
Hello and thanks for the fast replay.
Yes i used 100k Resistors
Here is my Code:
#include <EEPROM.h>
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
eepromWriteInt(2, 0);
eepromWriteInt(3, 0);
eepromWriteInt(4, 0);
eepromWriteInt(5, 0);
eepromWriteInt(6, 0);
eepromWriteInt(7, 0);
eepromWriteInt(8, 0);
eepromWriteInt(9, 0);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(2) == LOW) {
change(2);
}
if (digitalRead(3) == LOW) {
change(3);
}
if (digitalRead(4) == LOW) {
change(4);
}
if (digitalRead(5) == LOW) {
change(5);
}
if (digitalRead(6) == LOW) {
change(6);
}
if (digitalRead(7) == LOW) {
change(7);
}
if (digitalRead(8) == LOW) {
change(8);
}
if (digitalRead(9) == LOW) {
change(9);
}
}
void change(int port) {
if (eepromReadInt(port) == 0) {
Serial.print(port);
Serial.print("0");
analogpin(port, 0);
eepromWriteInt(port, 1);
while (digitalRead(port) == LOW) { delay(200); }
//delayMicroseconds(500);
return;
}
if (eepromReadInt(port) == 1) {
Serial.print(port);
Serial.print("1");
analogpin(port, 1);
eepromWriteInt(port, 0);
while (digitalRead(port) == LOW) { delay(200); }
//delayMicroseconds(500);
return;
}
}
void analogpin(int analog, int val) {
if ( analog == 2 && val == 0 ) { digitalWrite(11, HIGH);}
if ( analog == 2 && val == 1 ) { digitalWrite(11, LOW); }
if ( analog == 3 && val == 0 ) { digitalWrite(10, HIGH); }
if ( analog == 3 && val == 1 ) { digitalWrite(10, LOW); }
if ( analog == 4 && val == 0 ) { digitalWrite(A5, HIGH); }
if ( analog == 4 && val == 1 ) { digitalWrite(A5, LOW); }
if ( analog == 5 && val == 0 ) { digitalWrite(A4, HIGH); }
if ( analog == 5 && val == 1 ) { digitalWrite(A4, LOW); }
if ( analog == 6 && val == 0 ) { digitalWrite(A3, HIGH); }
if ( analog == 6 && val == 1 ) { digitalWrite(A3, LOW); }
if ( analog == 7 && val == 0 ) { digitalWrite(A2, HIGH); }
if ( analog == 7 && val == 1 ) { digitalWrite(A2, LOW); }
if ( analog == 8 && val == 0 ) { digitalWrite(A1, HIGH); }
if ( analog == 8 && val == 1 ) { digitalWrite(A1, LOW); }
if ( analog == 9 && val == 0 ) { digitalWrite(A0, HIGH); }
if ( analog == 9 && val == 1 ) { digitalWrite(A0, LOW); }
}
void eepromWriteInt(int adr, int wert) {
// 2 Byte Integer Zahl im EEPROM ablegen an der Adresse
// Eingabe:
// adr: Adresse +0 und +1 wird geschrieben
// wert: möglicher Wertebereich -32,768 bis 32,767
// Ausgabe:
// -
// 2 Byte Platz werden belegt.
//
// Matthias Busse 5.2014 V 1.0
byte low, high;
low=wert&0xFF;
high=(wert>>8)&0xFF;
EEPROM.write(adr, low); // dauert 3,3ms
EEPROM.write(adr+1, high);
return;
} //eepromWriteInt
int eepromReadInt(int adr) {
// 2 Byte Integer Zahl aus dem EEPROM lesen an der Adresse
// Eingabe:
// adr: Adresse +0 und +1 wird gelesen
// Ausgabe: int Wert
//
// Matthias Busse 5.2014 V 1.0
byte low, high;
low=EEPROM.read(adr);
high=EEPROM.read(adr+1);
return low + ((high << 8)&0xFF00);
} //eepromReadInt
Wawa:
100k pull up is ok. 100ohm wastes too much current.
But why use pull up resistors at all.
They are already inside the Nano chip.
You just have to enable them in code.
I would have connected the buttons between pin and ground.
NO resistors.
And use this in setup()
pinMode(buttonPin1, INPUT_PULLUP);
etc.
Leo..
Didn't work for me without the resistor