Go Down

Topic: Problema al subir programa a Arduino Mega 2560 (Read 820 times) previous topic - next topic

ING

Hola, acabo de recibir mi nuevo Arduino Mega 2560. Ante todo instalé los drivers que vienen con la versión 0021. Seleccioné la placa y el COM. Subí el típico programita del parpadeo del led y todo perfecto. Subí otro programa, en concreto este:

Code: [Select]
#include <Keypad.h>
#include <Password.h>

Password password = Password( "1337" );
int alarmCounter = 0;

const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {23, 28, 27, 25}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {24, 22, 26}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int enablePin = 2;
int motor11Pin = 3;
int motor12Pin = 4;
int motor21Pin = 5;
int motor22Pin = 6;
int rojo = 7;
int verde = 8;
int led = 9;
int speakerPin = 13;
const int analogPin = 0;
const int alarma = 1;
const int threshold = 970;
void alar();
#define c 261
#
#define d 294
#
#define e 329
#
#define f 349
#
#define g 391
#
#define gS 415
#
#define a 440
#
#define aS 455
#
#define b 466
#
#define cH 523
#
#define csH 554
#
#define dH 587
#
#define dsH 622
#
#define eH 659
#
#define fH 698
#
#define fsH 740
#
#define gH 784
#
#define gsH 830
#
#define aH 880
int ala = 0;

void setup(){
Serial.begin(9600);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);
 pinMode(motor11Pin, OUTPUT);
 pinMode(motor12Pin, OUTPUT);
 pinMode(motor21Pin, OUTPUT);
 pinMode(motor22Pin, OUTPUT);
 pinMode(rojo, OUTPUT);
 pinMode(verde, OUTPUT);
 
 
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
startupSound();
}
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)
{
   int x;      
   long delayAmount = (long)(1000000/frequencyInHertz);
   long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
   for (x=0;x<loopTime;x++)    
   {    
       digitalWrite(speakerPin,HIGH);
       delayMicroseconds(delayAmount);
       digitalWrite(speakerPin,LOW);
       delayMicroseconds(delayAmount);
   }    
 }
void loop(){
char key = keypad.getKey();
ala = analogRead(alarma);

if(ala > 150){  
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    beep(speakerPin, aH, 200);
    beep(speakerPin, fsH, 200);
    }
   
}



//take care of some special events
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
case PRESSED:
switch (key){
case '#': guessPassword();

break;
case '*': password.reset();
resetSound();

break;
default : if (key != NO_KEY){
Serial.print("Key Pressed = ");
Serial.println(key);
}
password.append(key);

analogWrite(speakerPin, 128);
break;
}
break;
case RELEASED:
switch (key){
default : digitalWrite(motor11Pin, LOW);
       digitalWrite(motor12Pin, LOW);
       digitalWrite(rojo, HIGH);
       delay(1000);
       digitalWrite(rojo, LOW);
       delay(1000);
break;
}
break;
}
}
void guessPassword(){
if (password.evaluate()){
abrir();
Serial.println("Password Correct");
password.reset();
alarmCounter = 0;
}else{
cerrar();
Serial.println("Password Incorrect!");
password.reset();
alarmCounter++;
if (alarmCounter >= 3){
alarmSound();
Serial.println("Alarm still active!");
Serial.println("Entering another wrong password will sound alarm again!");
Serial.println("To reset alarm please enter the right password!");
}else{
errorSound();
}
}
}
void alarmSound() {
Serial.println("Wrong password 3 time!");
Serial.println("Sounding ALARM!!!");
for (int aCount=0;aCount<5;aCount++){
   
}
}
void resetSound() {
int n = 100;
for (int vez=0;vez<6;vez++){
for (int _=0;_<100;_++){
delayMicroseconds(n);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(n);
digitalWrite(speakerPin, LOW);
}
delay(20);
}
}
void errorSound() {
int n = 2000;
for (int vez=0;vez<1;vez++){
for (int _=0;_<200;_++){
delayMicroseconds(n);
digitalWrite(speakerPin, HIGH);

delayMicroseconds(n);
digitalWrite(speakerPin, LOW);

}
delay(50);
}
}
void openSound() {
int n = 300;
for (int vez=0;vez<3;vez++){
for (int _=0;_<100;_++){
delayMicroseconds(n);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(n);
digitalWrite(speakerPin, LOW);
}
delay(100);
}
}
void startupSound() {
int note = (1/587.33)*500000;
for (int _=0;_<100000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
note = (1/659.26)*500000;
for (int _=0;_<100000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
note = (1/523.25)*500000;
for (int _=0;_<100000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
note = (1/261.63)*500000;
for (int _=0;_<100000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
note = (1/392.00)*500000;
for (int _=0;_<200000/note;_++){
delayMicroseconds(note);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(note);
digitalWrite(speakerPin, LOW);
}
}
void abrir(){
 digitalWrite(verde, HIGH);
          beep(speakerPin, aH, 500);
          delay(100);          
          digitalWrite(motor11Pin, HIGH);
          digitalWrite(motor12Pin, LOW);
          delay(2700);
          digitalWrite(motor11Pin, LOW);
          digitalWrite(motor12Pin, LOW);
          delay(1000);
          digitalWrite(motor21Pin, HIGH);
          digitalWrite(motor22Pin, LOW);
          delay(4000);
          digitalWrite(motor21Pin, LOW);
          digitalWrite(motor22Pin, LOW);
         
          delay(17000);
          beep(speakerPin, aH, 200);
          beep(speakerPin, fsH, 200);
          digitalWrite(verde, LOW);
         
          beep(speakerPin, aH, 200);
          beep(speakerPin, fsH, 200);
          digitalWrite(verde, HIGH);
         
          beep(speakerPin, aH, 200);
          beep(speakerPin, fsH, 200);
          digitalWrite(verde, LOW);
         
          beep(speakerPin, aH, 200);
          beep(speakerPin, fsH, 200);
          digitalWrite(verde, HIGH);
         
          beep(speakerPin, aH, 200);
          beep(speakerPin, fsH, 200);
          digitalWrite(verde, LOW);
         
          beep(speakerPin, aH, 200);
          beep(speakerPin, fsH, 200);
          digitalWrite(verde, HIGH);
          beep(speakerPin, aH, 200);
          beep(speakerPin, fsH, 200);
          digitalWrite(verde, LOW);
         
          beep(speakerPin, aH, 200);
          beep(speakerPin, fsH, 200);
          digitalWrite(verde, HIGH);
          delay(500);
          digitalWrite(motor21Pin, LOW);
          digitalWrite(motor22Pin, HIGH);
          delay(4000);
          digitalWrite(motor21Pin, LOW);
          digitalWrite(motor22Pin, LOW);
          delay(500);
          digitalWrite(motor11Pin, LOW);
          digitalWrite(motor12Pin, HIGH);
          delay(2700);
          digitalWrite(motor11Pin, LOW);
          digitalWrite(motor12Pin, LOW);
          delay(2000);
          digitalWrite(verde, LOW);
          delay(500);
}
void cerrar(){
 digitalWrite(motor11Pin, LOW);
       digitalWrite(motor12Pin, LOW);
       digitalWrite(rojo, HIGH);
       delay(1000);
       digitalWrite(rojo, LOW);
       delay(1000);
}


Y se queda pillado cuando lo intenta subir. He probado mil cosas. Mi ordenador tiene W7 de 64bits y nada. He probado en el portatil que tiene XP de 32bits y nada. He probado a subir otros programas (que no tienen librerias) y los sube rapidísimo. Pero el que yo quiero no  :-/

Gracias

ING

Solucionado, en parte. He tenido que quitar un poco de código y lo referente a él. En concreto este:

Code: [Select]
void alarmSound() {
Serial.println("Wrong password 3 time!");
Serial.println("Sounding ALARM!!!");
for (int aCount=0;aCount<5;aCount++){

}
}


De esta forma me ha dejado subirlo y ya no da error.

Saludos





Go Up