Show Posts
Pages: 1 ... 78 79 [80] 81 82 ... 291
1186  Using Arduino / Programming Questions / Re: lcd blink particular index variable on: March 10, 2014, 03:48:14 am
In my code example charToPrint was declared as a global char but you could declare it at the start of the loop() function as that is the only place that it is used.

I did not post all of the declaration and setup stuff because I have a different LCD and did not want to confuse things further but here is the whole program for my system
Code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3

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

unsigned long startedFlash;
unsigned long interval = 500;
char charToPrint = ' ';

void setup()
{
  lcd.begin (16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.clear();
  lcd.print("Hello World");
}

void loop()
{
  if (millis() - startedFlash > interval)
  {
    if (charToPrint == ' ')
    {
      charToPrint = 'o';
    }
    else
    {
      charToPrint = ' ';
    }
    startedFlash = millis();
    lcd.setCursor(4, 0);
    lcd.print(charToPrint);
  }
}
1187  Using Arduino / Programming Questions / Re: lcd blink particular index variable on: March 10, 2014, 03:29:17 am
So, what is it supposed to do and what does it really do ?
Where does getchar come into it as the variable does not appear in my program or yours.
1188  Using Arduino / Programming Questions / Re: using millis to get round delays inside an if statement (xylophone servo) on: March 09, 2014, 05:20:27 pm
ok cheers not quite sure I understand though

Code:
start of loop
  if start signal received and nowPlaying is false
    set timeStarted = millis()
    set nowPlaying to true
  end if

is now playing a boolean value ?

I found this code online for controlling the blinks of an LED

Code:
void loop()
{
  currentTime = millis();
  if(currentTime >= (loopTime + 1000)){  
    digitalWrite(ledPin, !digitalRead(ledPin));   // toggles the LED on/off
    loopTime = currentTime;  // Updates loopTime
  }

which I though I could replicate for each note (inside an if statement) changing the +1000 to correspond to the times of the notes?
In my pseudo code nowPlaying is a boolean.  I put it in to prevent any problems if the start signal occurred again or persisted when the note was already playing.

There is no reason for interval in my code to be a fixed value.  You could have two arrays, one with the note to be played and the other the duration of the note.  Using a common index into the array would allow a note to be played for the appropriate duration.
1189  Using Arduino / Programming Questions / Re: coding help on: March 09, 2014, 02:57:50 pm
If a test fails set a flag to indicate faulure.  Then check the flag before each test.  If it is set don't do the test.
1190  Using Arduino / Project Guidance / Re: Detecting a Change In Sign on: March 09, 2014, 02:54:07 pm
Each time you read the value save it.  Next time you read it compare it with the previous value.

if previous value greater than zero and current value less than zero the reading has gone from positive to negative
if current value greater than zero and previous value less than zero the reading has gone from negative to positive

I strongly suspect that there is a smarter way to do this ....
1191  Using Arduino / Programming Questions / Re: using millis to get round delays inside an if statement (xylophone servo) on: March 09, 2014, 02:24:47 pm
Don't bother setting millis() to zero, even if you can.  Just play the next note when enough time has elapsed
Code:
start of loop
  if start signal received and nowPlaying is false
    set timeStarted = millis()
    set nowPlaying to true
  end if
 
  if millis() - timeStarted > = interval
    play the next note
    set timeStarted = millis()
  end if
end of loop
1192  Using Arduino / Programming Questions / Re: coding help on: March 09, 2014, 02:12:58 pm
What do you mean by "stop the program if a test fails" ?
Taking this test for example
Code:
  if(val1 == HIGH)
  {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, LOW);
    delay(2000);
  }
  else
  {
    digitalWrite(led2, HIGH);
    digitalWrite(led1, LOW);
    delay(2000);
  }
What constitutes a failure and what should happen ?
1193  Using Arduino / Programming Questions / Re: lcd blink particular index variable on: March 09, 2014, 09:59:37 am
I am not going to reply to this thread until your current code is posted properly.
1194  Using Arduino / Programming Questions / Re: Arduino UNO sketch & push button on: March 09, 2014, 09:56:38 am
Some code to get you started
Code:
int state = 0;
const byte autoButtonPin = 2;
const byte manuButtonPin = 3;

void setup()
{
  pinMode(autoButtonPin, INPUT_PULLUP);
  pinMode(manuButtonPin, INPUT_PULLUP);
  Serial.begin(115200);
}

void loop()

  switch (state)
  {
  case 0:
    if (digitalRead(autoButtonPin) == LOW)
    {
      Serial.println("Auto button pressed.  Waiting for manual button to be pressed");
      state = 1;
    }
    break;

  case 1:
    if (digitalRead(manuButtonPin) == LOW)
    {
      Serial.println("Manual button has been pressed");
      state = 0;
    }
    break;
  }
}
1195  Using Arduino / Programming Questions / Re: arduino and ws2803 led driver on: March 09, 2014, 03:36:39 am
Can you please copy/paste your code from the IDE straight into code tags to avoid all the color crap ?
1196  Using Arduino / Programming Questions / Re: lcd blink particular index variable on: March 09, 2014, 02:46:27 am
Try this.  Not a delay() in sight because I presume that the program will need to do other things and not be blocked.
Code:
  lcd.setCursor(0, 0);
  lcd.print("Hello World");
}

void loop()
{
  if (millis() - startedFlash > interval)
  {
    if (charToPrint == ' ')
    {
      charToPrint = 'o';
    }
    else
    {
      charToPrint = ' ';
    }
    startedFlash = millis();
    lcd.setCursor(4, 0);
    lcd.print(charToPrint);
  }
}
Obviously you need to set up the variables appropriately but this is the loop that does the time checking and flashes the character.  There is a neater way to do it that I can think of but this one is very obvious as to how it works.
1197  Using Arduino / Programming Questions / Re: counter with counter on: March 08, 2014, 03:50:28 pm
Have you tried anything yourself ?

You will probably have discovered that you cannot use delay() for the 5 second period because it blocks execution of the code for the delay period so cannot read a pin or count pulses.  So, what to do ?  Have a look at the BlinkWithoutDelay example in the IDE.  You can adapt the method it uses to count how many times a pin goes from LOW to HIGH in a 5 second period.
1198  Using Arduino / Programming Questions / Re: Leonardo R3 problem with one dosing pump on boot up on: March 08, 2014, 03:01:49 pm
So, the problem still manifests itself on pin 12. 

The only difference I can see between pins 9, 10, 11 and pin 12 is that  the latter is not a PWM pin.  Why that should make a difference I don't know.  Can you swap the pin assignments around and put all of the motor outputs on PWM pins.  If nothing else it will eliminate PWM as a factor in the problem.
1199  Using Arduino / Programming Questions / Re: Where to Float and Trim Decimal Places on: March 08, 2014, 02:00:17 pm
Quote
I'm also confused as to your post. You posted Serial.println(difout, 2); twice and obtained two different results. Was the second example mistyped?
Sorry, yes.  The third example was from
Code:
Serial.println(difout, DEC);
1200  Using Arduino / Interfacing w/ Software on the Computer / Re: help with connect arduino with vb6 on: March 08, 2014, 01:54:56 pm
This is not the right place to ask for VB code, but this page will help with receiving the data on the Arduino and displaying it   http://gammon.com.au/serial
Pages: 1 ... 78 79 [80] 81 82 ... 291