Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Re: Use two 433Mhz library in the same sketch? on: October 28, 2013, 02:33:41 pm
ok i see, will probably be incompatible for that reason, will check for another solution.
Thanks
Mike
2  Using Arduino / Programming Questions / Use two 433Mhz library in the same sketch? on: October 28, 2013, 11:17:02 am
Hi,
     i use the rfswitch library for a long time to interface to arduino, could i use also the virtualwire in the sketch to? In my project, i have a main arduino that receive and send data to others arduino, some of them need more data so will like to use also the virtualwire library.

Thanks
Mike
3  Using Arduino / Programming Questions / Re: Make code more smaller on: October 24, 2013, 03:30:11 pm
Right on
Thank a lot
4  Using Arduino / Programming Questions / Re: Make code more smaller on: October 24, 2013, 02:25:28 pm
Yes i know but since DeviceAddress is declare in the 1-wire library, i could not access it like this
Code:
Serial.println(DeviceAddress[1]);
it say
error: expected primary-expression before '[' token
5  Using Arduino / Programming Questions / Re: Make code more smaller on: October 24, 2013, 02:11:42 pm
Thanks, understand now. now here a section of my code
Code:
// arrays to hold device addresses
DeviceAddress sensor1, sensor2, sensor3, sensor4, sensor5, sensor6, sensor7, sensor8, sensor9;
boolean sensor1_status = false;
boolean sensor2_status = false;
boolean sensor3_status = false;
boolean sensor4_status = false;
boolean sensor5_status = false;
boolean sensor6_status = false;
boolean sensor7_status = false;
boolean sensor8_status = false;
boolean sensor9_status = false;

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  mySwitch.enableTransmit(4);
  mySwitch.setRepeatTransmit(2);
  
  sensors.begin();
  if (sensors.getAddress(sensor1, 0)) sensor1_status = true;
  if (sensors.getAddress(sensor2, 1)) sensor2_status = true;
  if (sensors.getAddress(sensor3, 2)) sensor3_status = true;
  if (sensors.getAddress(sensor4, 3)) sensor4_status = true;
  if (sensors.getAddress(sensor5, 4)) sensor5_status = true;
  if (sensors.getAddress(sensor6, 5)) sensor6_status = true;
  if (sensors.getAddress(sensor7, 6)) sensor7_status = true;
  if (sensors.getAddress(sensor8, 7)) sensor8_status = true;
  if (sensors.getAddress(sensor9, 8)) sensor9_status = true;
  
  // set the resolution to 9 bit
  sensors.setResolution(sensor1, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor2, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor3, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor4, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor5, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor6, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor7, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor8, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor9, TEMPERATURE_PRECISION);
  Serial.println("No RF");
}

I want to do that in the for loop so there's no need to put all this code. The problem is with the Device address, how could i identify sensor one array with the sensor_statut
6  Using Arduino / Programming Questions / Make code more smaller on: October 24, 2013, 01:07:17 pm
Hi,
     is there a way to have less code to do this
Code:
boolean sensor1_status = false;
boolean sensor2_status = false;
boolean sensor3_status = false;
boolean sensor4_status = false;
boolean sensor5_status = false;
boolean sensor6_status = false;
boolean sensor7_status = false;
boolean sensor8_status = false;
boolean sensor9_status = false;

I want 9 variable with boolean value, is this the best way to declare it or there a better way with less coding and more speed.
Thanks in advance
Mike
7  Using Arduino / Programming Questions / Arduino with more i2c on: October 16, 2013, 04:17:31 pm
Hi,
     i want to use to library that use the analog pin 4 and 5 but the thing is that one is for the lcd and the second is for the ds1307. I want to keep the pin 0 and 1 for the serial communication. do you guy have some tips.

Thanks
8  Using Arduino / Programming Questions / Map millis to servo on: September 29, 2013, 11:18:32 am
Hi try to do a little timer for my son that have some time depending of the switch he press.
Here the code
Code:
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
int temps = 0;
const int buttonPin2 = 4;
const int buttonPin3 = 5;
int buttonState_2 = 0;
int buttonState_3 = 0;
int buton1time2 = 30000;
int buton1time3 = 60000;
long int millisstart;
long int millisend;
int second = 1000;
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
 Serial.begin(9600);
 
}
 
 
void loop(){
buttonState_2 = digitalRead(buttonPin2);
buttonState_3 = digitalRead(buttonPin3);
myservo.write(0);
if (buttonState_2 == LOW) {     
    temps = buton1time2;
  }
if (buttonState_3 == LOW) {     
    temps = buton1time3;
  }
if (temps != 0){
{
  millisstart = millis();
  millisend = (millisstart + temps);
    int val;
    while(millis() < millisend){
    val = millis();
    val = map(val,  millisstart, millisend, 0, 180);
    myservo.write(val);
    Serial.println(val);    // tell servo to go to position in variable 'pos'
    delay(250);
    }    // waits 15ms for the servo to reach the position
    temps = 0;
  }
 
 
}
}
Code work good with the 30 second but when i try 60 second it does not work, when i check the val on the serial, i receive some strnge value.
Thanks in advance
9  Using Arduino / Programming Questions / Re: Need some tips for code on: September 27, 2013, 07:55:40 pm
Hi end up with this
Code:
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

int Relay[]={0,3,4,5,6,7,8,9,13};
int value;
int protocole;
String sensorID;
String state;
String activate;

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  for(byte i=1; i<9; i++)
{
   pinMode(Relay[i], OUTPUT);
}
}

void loop() {
  if (mySwitch.available()) {
   
    value = mySwitch.getReceivedValue();
    protocole =mySwitch.getReceivedProtocol();
    String code = String(value);
    activate = code.substring(0,2);
    if ((activate == "99") && (protocole == 1)){
    int length = code.length();
    sensorID = code.substring(2,length-1);
    state    = code.substring(length-1);
    if (state == "1"){
       int test = sensorID.toInt();
       digitalWrite(Relay[test], HIGH);
    }
    else if (state == "0"){
      int test = sensorID.toInt();
      digitalWrite(Relay[test], LOW);
    }
    delay(500);
    mySwitch.resetAvailable();
   
    }
  }
}
10  Using Arduino / Programming Questions / Re: Need some tips for code on: September 27, 2013, 07:30:19 pm
Thanks,
           so the bytes will correspond to the sensorID? if so could i skip the bytes 0 since sensorID will correspond to the bytes?
Again thanks
11  Using Arduino / Programming Questions / Need some tips for code on: September 27, 2013, 04:50:07 pm
Hi all,
        i have a sketch that receive code that is a string to control relay, the code look like this, 9910 9911. Then the string trim
string activate = 99, string sensorID = 1, string state = 0. here the code:
Code:
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

int Relay_1 = 13;
int Relay_2 = 4;
int Relay_3 = 5;
int Relay_4 = 6;
int Relay_5 = 7;
int Relay_6 = 8;
int Relay_7 = 9;
int Relay_8 = 10;
int value;
int protocole;
String sensorID;
String state;
String activate;

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  pinMode(Relay_1, OUTPUT);
  pinMode(Relay_2, OUTPUT);
  pinMode(Relay_3, OUTPUT);
  pinMode(Relay_4, OUTPUT);
  pinMode(Relay_5, OUTPUT);
  pinMode(Relay_6, OUTPUT);
  pinMode(Relay_7, OUTPUT);
  pinMode(Relay_8, OUTPUT);
}

void loop() {
  if (mySwitch.available()) {
   
    value = mySwitch.getReceivedValue();
    protocole =mySwitch.getReceivedProtocol();
    String code = String(value);
    activate = code.substring(0,2);
    if ((activate == "99") && (protocole == 1)){
    Serial.println(value);
    int length = code.length();
    sensorID = code.substring(2,length-1);
    state    = code.substring(length-1);
    Serial.println(state);
    if (state == "1"){
       digitalWrite(Here were when sensorID is 1 i want Relay_1, HIGH);
    }
    else if (state == "0"){
      digitalWrite(Relay_1, LOW);
    }
    delay(1500);
    mySwitch.resetAvailable();
   
    }
  }
}
   
So sensorID will be 1=Relay_1, 2 Relay_2 and so on. Where i'm stock is how to replace the Relay_1 by the string.Not sure if i'm clear enough but this is my problem, when sensorid is 1, relay_1 pin will be use, when 2 relay_2 pin will be used.
Thanks
 
12  Using Arduino / Programming Questions / Re: Use substring from right on: September 24, 2013, 12:02:04 pm
You are right, thanks for the tips,
I use:
Code:
int length = myString.length();
To determinate the length and after that it was a piece of cake.
Thanks again
13  Using Arduino / Programming Questions / Use substring from right on: September 24, 2013, 11:38:23 am
Probaby a stupid question but how to use this fonction but from the right? in some language you just have to use the minus but it seems not to work with the substring.
Code:
String test = 12345688
I want to slipt the string from the last 2 digit, so 123456 and 88. The length of the string may vary so that why i want to go from the right so it will alway be the 2 last digit that will be split. I saw on the forum that it could maybe be achived by dtostrf() but didn't saw a good explanation. And for sure i want to keep this in String
Thanks
14  Using Arduino / Programming Questions / substring from right on: September 12, 2013, 09:24:46 am
Hi,
    have data that come from the 1-wire library, since i can't convert easily a float to a string, i multiply the float by 100 to a int and then convert it to a string, this seems to work good event with the minus. now i want to reconstruct the sting with the comma.so i will like to use the substring but from the right side since the length of the string is not always equal and the precision is set always to 2 number after the comma.
Here the code
Code:
int temperature = sensors.getTempC(deviceAddress) * 100;
     String test(temperature);
     String test2 = test.substring(-2);
     Serial.print(test2);
     String devcount(sensors.getDeviceCount(), DEC);

Thanks
15  Using Arduino / Programming Questions / Re: add number to long int on: September 10, 2013, 02:53:51 pm
The thing is that the code length is not always equal, so 1000000 + sensor code does not work, is there a function that i could use. It simple, all i want is to add 1 before the code to identify what kind of sensor is it.
Pages: [1] 2 3 ... 5