Recent Posts

Pages: 1 ... 6 7 [8] 9 10
71
Proyectos / Codigo-interpretacion
Last post by lucasdanielisa - Today at 03:59 am
Me podrian ayudar a interpretar este codigo.
#include <SoftwareSerial.h>
SoftwareSerial BT(7,8);//10 RX, 11 TX.
 void setup()
{
 Serial.begin(9600);
 BT.begin(9600);
 Serial.flush();
 pinMode(3,OUTPUT);
 pinMode(5,OUTPUT);
 pinMode(6,OUTPUT);
 pinMode(9,OUTPUT);
 pinMode(10,OUTPUT);
 pinMode(11,OUTPUT);
}
void loop()
{
 Serial.flush();
 if(BT.available()<1) return;
 char get_char = BT.read();
 if (get_char != '*') return;
 int dato=BT.parseInt();
 int pin=BT.parseInt();
 int valor=BT.parseInt();
 Serial.println(dato);
 Serial.println(pin);
 Serial.println(valor);
 if(dato == 11)
 {
 analogWrite(pin,valor);
 }
 if (dato == 10)
 {
 if (valor == 2)
 {
 valor = LOW;
 digitalWrite(pin, valor);
 }else if (valor == 3)
 {
 valor = HIGH;
 digitalWrite(pin, valor);
 }
 }
}
72
You can buy Bluetooth 4.0 related boards (BLEduino,BLE Bee, BLE shield) here.
73
Code: [Select]
    checkEntered1(1); //call checkEntered and pass it a 1
Really? I'd have never guessed.

Code: [Select]
  if (entered[0] != 0)
  {
  }
  else if(entered[0] == 0){ //if it is zero, i.e. if it hasn't been defined with a button yet

If the value is not 0, is there a snowballs chance in hell that it will change to 0 before you check again?

Code: [Select]
     for (int x = 0; x++;);
You REALLY need to explain this. A for loop has THREE clauses and NO semicolon.
74
Software / Re: Lograr endender y apagar L...
Last post by gepd - Today at 03:51 am
Yo creo que debes tener algo mal conectado, yo lo probé y me funciona el boton y los comando por serie.

- Si presiono el botón 1 vez, se enciende el led, si lo presiono otra vez se apaga.
- Si presiono el boton 1 vez, se enciende el led, si escribo Led1_OFF el led se apaga.
-Si escribo Led1_ON, el led se enciende, si presiono el botón, el led se apaga.


y así...


esto es lo que entendí que querías y así está funcionando.
no entiendo cual es el problema que estás teniendo.
75
Programming Questions / Question Regarding a Distance ...
Last post by Ibro - Today at 03:50 am
Basically I am creating an alarm that is triggered when my distance sensor reads a value under a certain threshold. I got the activation code working, where you have to press 4 buttons in a correct sequence to activate the alarm. Now what I am trying to do is to disable the alarm, while it is running (playing a tone and red LED is on), with the same code that you turned it on with. I can't really think of an easy way to do that, so I just tried to take the code that reads the buttons and checks if the sequence is correct and put it into the alam(); portion of my code. This returns with:

Alarm_final:205: error: a function-definition is not allowed here before '{' token
Alarm_final:258: error: expected `}' at end of input

Any better ideas on how to get this to work or how to fix the error code?

Also, this is not my entire code, I wasn't able to put it all in the post because it would exceed the 9000 character limit. If you need to know more about what I am trying to do, please message me, I am really stuck on this one.

This is my code:

Code: [Select]
#include <DistanceSRF04.h>

#include <NewPing.h>
#include <NewTone.h>
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters).
#define ALARM 3
float sinVal;
int toneVal;
boolean triggered = false;
int calibrationTime = 30;       
long unsigned int lowIn;         
long unsigned int pause = 5000; 
boolean lockLow = true;
boolean takeLowTime; 
int pirPin = 5;
DistanceSRF04 Dist;
int distance;
int button1 = 8; //first button is on pin 8
int button2 = 9; //second is on pin 9
int button3 = 10; //third is pin 10
int button4 = 11; //fourth is pin 11
int redLed = 4; //red LED is on pin 4
int greenLed = 12; //green LED is pin 12
int pinSpeaker = 6; //speaker LED is pin 13

int code[] = {1,2,3,4}; //the desired code is entered in this array,
                        //separated by commas

int entered[4]; //create a new empty array for the code entered by
                //the user (has 4 elements)

void setup(){ //run once at sketch startup
  Serial.begin(9600); //begin Serial

  pinMode(button1, INPUT); //button 1 is an input
  pinMode(button2, INPUT); //button 2 is an input
  pinMode(button3, INPUT); //button 3 is an input
  pinMode(button4, INPUT); //button 4 is an input
  pinMode(redLed, OUTPUT); //the red LED is an output
  pinMode(greenLed, OUTPUT); // the green LED is an output
  pinMode(pinSpeaker,OUTPUT);//the speakerpin is an output
  setupLights(); //run the setupLights routine
  setupLights(); //run it again
  delay(650); //delay (only for effect, :P not needed)
  digitalWrite(redLed, HIGH); //turn the red LED on
  Dist.begin(2,3);

  //give the sensor some time to calibrate
  //Serial.print("calibrating sensor ");
   // for(int i = 0; i < calibrationTime; i++){
     // Serial.print(".");
      //delay(1000);
      //}
   // Serial.println(" done");
   // Serial.println("SENSOR ACTIVE");
    //delay(50);
}

void loop(){ //run repeatedly
  if (digitalRead(button1) == LOW){ //if button1 is pressed
    checkEntered1(1); //call checkEntered and pass it a 1
    delay(250);//wait, needed for correct functioning, otherwise
               //buttons are deemed to be pressed more than once
  }
  else if (digitalRead(button2) == LOW){ //if button2 is pressed
    checkEntered1(2); //call checkEntered1 and pass it a 2
    delay(250); //wait
  }
  else if (digitalRead(button3) == LOW){ //if button3 is pressed
    checkEntered1(3); //call checkEntered1 and pass it a 3
    delay(250); //wait
  }
  else if (digitalRead(button4) == LOW){ //if button4 is pressed
    checkEntered1(4); //call checkEntered1 and pass it a 4
    delay(250); //wait
  }

}

void checkEntered1(int button /* define the 1,2,3 or 4 as an integer called button */){ //check the first element of the entered[] array
  if (entered[0] != 0){ //if it is not a zero, i.e. it has already been inputted
    checkEntered2(button); //move on to checkEntered2, passing it "button"
  }
 
  else if(entered[0] == 0){ //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[0] = button; //set the first element as the button that has been pressed
    Serial.print("1: ");Serial.println(entered[0]); //for debugging
  }
 
}

void checkEntered2(int button){ //check the second element of the entered[] array
  if (entered[1] != 0){ //if it is not a zero, i.e. it has already been inputted
    checkEntered3(button); //move on to checkEntered3, passing it "button"
  }
 
  else if(entered[1] == 0){ //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[1] = button; //set the second element as the button that has been pressed
    Serial.print("2: ");Serial.println(entered[1]); //for debugging
  }
 
}

void checkEntered3(int button){  //check the third element of the entered[] array
  if (entered[2] != 0){ //if it is not a zero, i.e. it has already been inputted
    checkEntered4(button); //move on to checkEntered4, passing it "button"
  }
 
  else if (entered[2] == 0){ //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[2] = button; //set the third element as the button that has been pressed
    Serial.print("3: ");Serial.println(entered[2]); //for debugging
  }
 
}

void checkEntered4(int button){ //check the fourth element of the entered[] array
  if (entered[3] == 0){ //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[3] = button; //set the final element as the button that has been pressed
    Serial.print("4: ");Serial.println(entered[3]); //for debugging
    delay(100); //allow time for processing
    compareCode(); //call the compareCode function
  }
}

void compareCode(){ //checks if the code entered is correct by comparing the code[] array with the entered[] array
 
  if ((entered[0]==code[0]) && (entered[1]==code[1]) && (entered[2]==code[2]) && (entered[3]==code[3])){ //if all the elements of each array are equal
   
     for (int x = 0; x++;);
     alarmCode();
  }
 
  else { //if you (or the intruder) get the code wrong
    flash(); //call the flash function
    }
}   
void flash(){ // this is basically the blink example, look at that for an explantion of this, I wont insult your intelligence... oh wait, I already did that earlier when explaining the green LED flashing... sorry 'bout that
  digitalWrite(redLed, LOW);
  delay(250);
  digitalWrite(redLed, HIGH);
  delay(250);
  digitalWrite(redLed, LOW);
  delay(250);
  digitalWrite(redLed, HIGH);
  delay(250);
  digitalWrite(redLed, LOW);
  delay(250);
  digitalWrite(redLed, HIGH);
  delay(250);
  digitalWrite(redLed, LOW);
  delay(250);
  digitalWrite(redLed, HIGH);
  delay(250);
}

void setupLights(){ // a funky display run at reset
  digitalWrite(redLed, HIGH); //turn both
  digitalWrite(greenLed, HIGH); //LEDs on
  delay(75); //wait
  digitalWrite(redLed, LOW); //turn them
  digitalWrite(greenLed, LOW); //off again
  delay(75); //wait
}

void alarmCode(){
  digitalWrite(greenLed,HIGH);
  for (int i = 0; i<10000; i++){
    if(triggered == true){
      alarm();
    }
    else{
      delay(50);// Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
    }
      if(distance < 50){
         triggered = true;
      }
    }
  }
 
void alarm(){
  digitalWrite(greenLed,LOW);
  digitalWrite(redLed,HIGH);
  for (int i=0; i<100000; i++){
    tone(6, 3000);
 if (digitalRead(button1) == LOW){ //if button1 is pressed
    checkEntered1(1); //call checkEntered and pass it a 1
    delay(250);//wait, needed for correct functioning, otherwise
               //buttons are deemed to be pressed more than once
  }
  else if (digitalRead(button2) == LOW){ //if button2 is pressed
    checkEntered1(2); //call checkEntered1 and pass it a 2
    delay(250); //wait
  }
  else if (digitalRead(button3) == LOW){ //if button3 is pressed
    checkEntered1(3); //call checkEntered1 and pass it a 3
    delay(250); //wait
  }
  else if (digitalRead(button4) == LOW){ //if button4 is pressed
    checkEntered1(4); //call checkEntered1 and pass it a 4
    delay(250); //wait
  }

}

void checkEntered1(int button /* define the 1,2,3 or 4 as an integer called button */){ //check the first element of the entered[] array
  if (entered[0] != 0){ //if it is not a zero, i.e. it has already been inputted
    checkEntered2(button); //move on to checkEntered2, passing it "button"
  }
 
  else if(entered[0] == 0){ //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[0] = button; //set the first element as the button that has been pressed
    Serial.print("1: ");Serial.println(entered[0]); //for debugging
  }
 
}

76
Programming Questions / Re: how join two codes
Last post by PaulS - Today at 03:49 am
Quote
I want to unite and work with one arduino
What do you want the resulting program to do?

What have you tried?

Do you really understand what either code is doing? If so, it is trivial to combine them, as long as you know what you want the final program to do.
77
Project Guidance / Re: Mega 2560 with Serial Barc...
Last post by denbrown - Today at 03:49 am
Sorry, I did not see much information on your post about the Serical Barcode Scanner issue. So would you give some more information about what barcode reading effects that you are trying to achieve.
Hi, Does it support PDF417 and UPC-A? I need such a tool for scanning driving licenses, my sisters' market also need it.
78
Project Guidance / Re: IR Remote Bulldozer Bot
Last post by JimboZA - Today at 03:48 am
it gave me several error messages.
You should list them here...

Quote
I just need to know in which included part the frequencies are declared.
I'm not sure what that means
79
Software / Re: como unir dos codigos
Last post by PaulS - Today at 03:47 am
Quote
el problema es
The problem is that you STILL need a map. This is the English section of the forum.
80
I'm using a Lenardo clone

SPI is hardware
0 - serial
1 - serial
2 - LCD CS
3 - Fan PWM
4 - LCD DC
5 - Fan PWM
6 - Fan PWM
7 - LCD Reset
8 - One wire bus (thermometers)
9 - Fan PWM
10 - Fan PWM
11 - Fan PWM
12 - Fan TACH
13 - Lcd backlight PWM

A0 Fan TACH
A1 Fan TACH
A2 Fan TACH
A3 Fan TACH
A4 Fan TACH
A5 Analog Button

I have pondered using a multiplexer to read the fan tach - I also pondered using DS2423's for the tach but they don't exist any more.

I could use an ATTiny13 for the tach also but truth be told I only need to check every now and then to make sure the fans are actually spinning so as to sound an alarm.
Pages: 1 ... 6 7 [8] 9 10