Hello, I'm new to this Arduino thing and I don't understand much about the basics of its programming, I recently tried to run this code that I took from a YouTube video, the guy only left a link to his page with the code and at no time did he talk about the code.
This is from the page with the code, if someone can help tell me what is wrong with the code I will be eternally grateful!!!
Maybe you can indicate what the problem is that you have? Does it not compile? Can't you upload? If you can upload, what do you expect it to do and what does it do that you did not expect it to do?
Remember also always, when it is for a school project, to mention how long the project has been going on or when was the assignment given. And when is the assignment due. Why? Because it usually gives a very good picture of how committed you are to learning something.
char contrasena[]="1234"; //NUMERO DE LA CONTRASEĆA
char codigo[4];
int cont=0;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo servomotor;
int valor; when i quit this valor ''br'', this problem appear: a function-definition is not allowed here before '{' token
void setup(){ and the error jumps here
servomotor.attach(11,1000,2000);
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
servomotor.write(0);
if (customKey != NO_KEY){
codigo[cont]=customKey;
Serial.print(codigo[cont]);
cont++;
if(cont==4){
if(codigo[0]==contrasena[0]&&codigo[1]==contrasena[1]&&codigo[2]==contrasena[2]&&codigo[3]==contrasena[3]){
digitalWrite(13,!digitalRead(13));
Serial.println(" ContraseƱa correcta");
servomotor.write(180);
delay(5000); //TIEMPO QUE SE MANTIENE SUBIDA LA BARRERA (en ms)
servomotor.write(0);
}
else if(codigo[0]!=contrasena[0]||codigo[1]!=contrasena[1]||codigo[2]!=contrasena[2]||codigo[3]!=contrasena[3]){
Serial.println(" ContraseƱa incorrecta");
}
cont=0;
}
}
}
Use the Auto Format function in the Arduino IDE editor: ctrl + T
Copy-paste your code here after using ctrl + T.
Use code tags around your code here. Highlight all your code but not your text you write here, and click on this button:
If you don't follow these rules, everyone will think you're just an arrogant pupil trying to make other do his homework. I have a feeling J-M-L thinks so.