Show Posts
Pages: 1 ... 78 79 [80] 81 82 ... 274
1186  Using Arduino / Programming Questions / Re: Not able to generate continous pulse using delay in microseconds and in millisec on: February 10, 2014, 11:52:36 am
Quote
i found that the pulses are not coming in continuous form
How are they coming if not continuously ?
1187  Using Arduino / Programming Questions / Re: Servo rotation help on: February 10, 2014, 11:46:24 am
Pooh !
Of course it should be pinMode().  Thanks for the correction.  I will leave my mistake in place so that subsequent comments make sense.
1188  Using Arduino / Programming Questions / Re: ENCODER HOW TO ENCREASE THE PRECISION ,? on: February 10, 2014, 11:43:30 am
Code:
And about attach interrupt (0,increment,RISING) inside loop while
It's just to know how many rising i have during period t to calcul the speed.
Once the interrupt is attached it will not be explicitly detached unless you do it so you only need to do it once.  Doing it 20 times achieves nothing.
1189  Using Arduino / Programming Questions / Re: Servo rotation help on: February 10, 2014, 11:34:08 am
Depending on the servo it may be drawing too much current.  Can you try powering it from a completely separate source such as 4 AA batteries, making sure that you have a common GND.

I tried your code using buttons for inputs having made a couple of changes to take account of the pins I used and the fact that I used the Arduino internal pull up resistors on the inputs.  The program works fine for me with this setup.  Can I suggest that you try it for yourself using buttons or breadboard leads that you can use to take the button inputs HIGH or LOW as appropriate.  This avoids the need to use actual buttons for testings, as does the INPUT_PULLUP parameter for setMode(), which activates the internal pull up resistors.

Here is the code that I tested.
Code:
#include <Servo.h>
int button1 = 7;
int press1 = 0;
int button2 = 8;
int press2 = 0;
Servo servo1;
int pos = 10;

void setup()
{
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  servo1.attach(9);
  Serial.begin(115200);
  servo1.write(10);
}

void loop()
{
  if ( (digitalRead(button1) == LOW) && (pos == 10) )
  {
    for (pos = 10; pos < 100; pos +=1)
    {
      servo1.write(pos);
      Serial.println(pos);
      delay(15);
    }
  }

  if ( (digitalRead(button2) == LOW) && (pos == 100) )
  {
    for (pos = 100; pos > 10; pos -=1)
    {
      servo1.write(pos);
      Serial.println(pos);
      delay(15);
    }
  }
}
1190  Using Arduino / Programming Questions / Re: {SOLVED} How to hold last increment value on: February 10, 2014, 03:13:46 am
Code:
{y=y;}
Why bother ?
1191  Using Arduino / Programming Questions / Re: Servo rotation help on: February 10, 2014, 02:18:17 am
In previous code you were testing the pos variable after for loops but it was never the value that you expected because of the way that the for loop end condition was constructed.  That is now fixed but your test for the initial value of pos is flawed.

pos is initially set to zero, so testing to see whether it is 10 or 100 will never be true.  Change the initial value of pos to 10 and try again.

How is the RF receiver powered and does it have  common GND with the Arduino ?  If not then there will be no point of reference for the Arduino to measure HIGH and LOW.
1192  Using Arduino / Programming Questions / Re: Help coding two sensors triggering LEDS on: February 09, 2014, 05:41:17 pm
Quote
when I leave my hands for longer period in front of the sensors the LEDs switch on suddenly again
If you look back at reply #1 you will see that I suggested actions should be taken when a sensor goes HIGH, ie changes from LOW to HIGH.  Your current code takes actions when a sensor is HIGH so if you leave your hand in place it will see the HIGH signal again and take the actions again. 

What you need to do when a sensor is seen to be HIGH is to check that its previous state was LOW.  To do this you need to remember the state of the sensor the last time you read it.  This process is known as state change detection and there is an example of it in the IDE.

Nothing to do with this problem, but you can drastically reduce the complexity of your ON/OFF functions by using an array and passing parameters to a single function.
1193  Using Arduino / Programming Questions / Re: LCD Scroll Text on: February 09, 2014, 12:25:34 pm
Roll your own scroll example.
Code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

const byte i2cAddress = 0x27;
const byte backlightPin= 3;
char * message = "Scroll me";

LiquidCrystal_I2C lcd(i2cAddress);  //NOTE library changed by BB to hard code pin numbers

void setup()
{
  lcd.begin (16,2);
  Serial.begin(115200);
  lcd.setBacklightPin(backlightPin ,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.setCursor(3,0);
  lcd.print("Stay Still");
}

void loop()
{
  for (int printStart = 15; printStart >= 0; printStart--)  //scroll on from right
  {
    showLetters(printStart, 0);
  }

  for (int letter = 1; letter <= strlen(message); letter++)  //scroll off to left
  {
    showLetters(0, letter);
  }
}

void showLetters(int printStart, int startLetter)
{
  lcd.setCursor(printStart,1);
  for (int currentLetter = startLetter; currentLetter < strlen(message); currentLetter++)
  {
    lcd.print(message[currentLetter]);
  }
  lcd.print(" ");
  delay(250);
}
Note that this is written for an I2C LCD so the initialisation will be need to be changed to suit yours, and as currently written the scrolling message cannot be wider than the LCD,  but that could be fixed.
1194  Using Arduino / Programming Questions / Re: Need help parsing serial data stream please. on: February 08, 2014, 05:27:29 pm
Quote
Not the same thing at all.
Especially since one is true and one is not.
That was my point.
1195  Using Arduino / Programming Questions / Re: Need help parsing serial data stream please. on: February 08, 2014, 04:13:11 pm
Quote
string functions are quite slow.
Do you mean String functions are quite slow or string functions are quite slow ?  Not the same thing at all.
1196  Using Arduino / Programming Questions / Re: Need help parsing serial data stream please. on: February 08, 2014, 02:04:59 pm
Build a string from the incoming characters then when it is complete (you need an end of message indicator) use strtok to split it at the commas then you can split each substring and turn the number strings into numbers using the strtof function if you actually need the numbers, otherwise just display the number substrings.

Note that several of your not integers.
1197  Using Arduino / Programming Questions / Re: check if serial-input contains string on: February 08, 2014, 01:57:28 pm
Code:
        if (inputString.substring(0)=="newrfid")
How many characters does inputString.substring(0) return ?
1198  Using Arduino / Programming Questions / Re: why dosent this code (Read integers from serial) work?? on: February 08, 2014, 09:33:26 am
Quote
And on the receiver side, i will have something that looks for the "T", and only then tries to parse the digits to integers??
You could do something like that by putting the characters into an array as they are received and then parsing the string. when the termination character is received. This is a good idea, but it will not solve the problem of trying to read from Serial when there is nothing there to read.  At the moment you check that Serial.available() is greater than zero and immediately assume that there are several characters available by using parseInt().  Before reading from Serial you must test to know that at least one character is available.
1199  Using Arduino / Programming Questions / Re: help with want a controlled signal on: February 07, 2014, 02:50:20 pm
Code:
#include <sensepin = 0>                                   
#include <sensepinh = 7>///////extra temperature censor attached to car
#include <sensepina = 8>/////connected to engine oil sensor
#include <sensepinb = 9>///connectd to engine  water bottle
#include <sensepinc = 10>///////extra temperature cut out switch attached to car
I read this far into your code then stopped.  What are these lines of code supposed to do ?
1200  Using Arduino / Programming Questions / Re: ENCODER HOW TO ENCREASE THE PRECISION ,? on: February 07, 2014, 02:00:11 pm
Code:
void encoder(const int piste_A, const int piste_B)
{

  attachInterrupt(0,direction_speed, RISING);
}
What is this function supposed to be doing ?  It is supplied 2 parameters that are never used in the function and attaches an interrupt each time through the loop() function when it only needs to be attached once in setup()

Then, later on, in the middle of the ISR you attach the same interrupt to another routine 20 times
Code:
  while(i<20)
  {
    attachInterrupt(0,increment,RISING);

    i=i+1;
  }
What's that all about ?

Later in the same ISR you attempt to print a variable that is not defined even though Serial.print() does not work in an ISR because interrupts are disabled.
Code:
  Serial.println(vitesse);
Pages: 1 ... 78 79 [80] 81 82 ... 274