Show Posts
Pages: 1 ... 5 6 [7] 8 9 ... 234
91  Using Arduino / LEDs and Multiplexing / Re: Programing RGB different colors on: April 06, 2014, 02:14:33 am
I would guess that the RGB values required will vary between different LEDs so it will not be possible to give absolute values in isolation.  How about writing a small program to read 3 analogue inputs, each with a pot on them, and have the input values adjust the PWM outputs.  Print the PWM values on the serial monitor and note them when you are happy with the output, then hard code them into your final program.
92  Using Arduino / Programming Questions / Re: How arudino execute commands on: April 06, 2014, 01:19:04 am
The Arduino will execute all of the instructions inside a for loop each time through the loop so it is no surprise that putting more instructions in the loop causes it to perform less loops per second.  Having said that, the difference that you are seeing is dramatic which must mean that the extra instructions are taking a long time to execute.

Please post your program with the extra instructions in the loop.

93  Using Arduino / Programming Questions / Re: Two press switches? on: April 05, 2014, 09:30:14 am
Quote
Could I add another one to change the pattern again?
Yes, or you could even use the same switch to change the pattern again, and again, and again.......

Why not post your current code as a starting point ?
94  Using Arduino / Programming Questions / Re: High speed photogate readings and hardware interrupts (Help Needed) on: April 05, 2014, 01:51:16 am
A suggestion.  Write a test program that does nothing else but read the photosensor and light an LED for a short period when it detects a dart passing.  Does it work OK ?
95  Using Arduino / Programming Questions / Re: Can I change the pins when I use the library LiquidCrystal on: April 04, 2014, 01:31:31 am
You should be able to use any pins available except 0 and 1 as long as you change the parameters when you create an instance of the LCD.  Try changing the pin assignments in a simple program first such as the LiquidCrystal Hello World example.
96  Using Arduino / Programming Questions / Re: Programming for autonomous obstacle avoidable robot on: April 04, 2014, 01:14:34 am
I have not looked through your code because you still have not used code tags when posting it, but I could not help noticing this line
Code:
int stateStop=1/2/3/4/5;
Can you explain what you are trying to do ?
97  Using Arduino / Programming Questions / Re: How to properly use an if statment on: April 03, 2014, 03:39:38 pm
When you say
Quote
sensors under the line
do you actually mean sensors over the line ?

All through this thread I have never understood why you needed so many sensors.
98  Using Arduino / Programming Questions / Re: High speed photogate readings and hardware interrupts (Help Needed) on: April 03, 2014, 03:35:18 pm
Thanks for the code but I am afraid that I am none the wiser as to what you want to do.  From your original description it would seem that you want to know how many shots have been fired or how many shots remain.  If that is not it then can you please explain in more detail ?

I freely admit that you could write what I know about Nerf guns in very big letters on the head of a pin, so I apologise for the question if it is not relevant, but could you not just count the number of times the trigger is pressed ?
99  Using Arduino / Programming Questions / Re: High speed photogate readings and hardware interrupts (Help Needed) on: April 03, 2014, 10:48:00 am
Will you please post all of your code so that what you are doing can be seen in context of the data types and sensor reading techniques being used ?  Details, a link maybe, of the 'photogate' that you are using and how things are wired would be helpful too.
100  Using Arduino / Programming Questions / Re: LED fade out when button pressed on: April 03, 2014, 06:01:50 am
You presumably mean
Code:
if(digitalRead(buttonPin) == HIGH)
  {
    //fading code goes here
  }
101  Using Arduino / Programming Questions / Re: PLC pulse command equivalence on: April 03, 2014, 05:56:21 am
@UKHeliBob that was the previous version I did that to not the last one I posted
The message I quoted, including the code, is the last code you posted as far as I can see.
102  Using Arduino / Programming Questions / Re: stop loop on: April 03, 2014, 02:00:51 am
Or don't use a for loop at all
Code:
byte n = 0;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  while (n < 5)
  {
    Serial.println(n);
    n++;
  }
}
103  Using Arduino / Programming Questions / Re: Need help saving user input to read back at a later time (array?) on: April 03, 2014, 01:54:37 am
Agreed.  The end of sequence marker is not necessary, but I quite like the idea as it is a very understandable technique, and the OP will encounter C style strings where a similar marker is absolutely necessary
104  Using Arduino / Programming Questions / Re: PLC pulse command equivalence on: April 03, 2014, 01:34:12 am
@ UKHeliBob, thanks so much for your help. I did a quick read of case instructions and changed the code as follows:

Code:
const int photoPin = 2; //byte or int for digital input???
const byte buzzerPin = 12;
byte state = 0;
unsigned long buzzerStart = 0;
unsigned long waitFiveMinsStart = 0;
unsigned long buzzerPeriod = 1000UL;
unsigned long fiveMinutePeriod = 10000UL; //changed to 10sec for testing

void setup()
{
  Serial.begin(115200);// Delete?? Not required??
  pinMode(buzzerPin, OUTPUT);
  pinMode(photoPin, INPUT); // added to read photoPin 2
}

void loop()
{
switch (state)
{
 
  case 0:                              //do nothing until the beam is broken
    if (photoPin, HIGH);   //adjust value or change to digitalRead if appropriate
    {
      state = 1;
      digitalWrite(buzzerPin, HIGH);   //turn on the buzzer
      buzzerStart = millis(); 
    }
   break;

  case 1:                              //buzzer sounds for one second
    if (millis() - buzzerStart >= buzzerPeriod)
    {
      state = 2;
      digitalWrite(buzzerPin, LOW);    //turn off the buzzer
      waitFiveMinsStart = millis();
    }
   // break;

  case 2:                              //do nothing until five minutes has elapsed
    if (millis() -  waitFiveMinsStart >= fiveMinutePeriod)
    {
      state = 0;
    }
   // break; 
  }
}

It doesn't work properly I have added comments, but this looks like I am not far from achieving my goal.
Why did you comment out the breaks ?  They are important to stop the case statement falling through to the next case.
105  Using Arduino / Programming Questions / Re: What's the best button debounce method for this code? on: April 03, 2014, 01:29:51 am
Your code with my comments on problems
Code:
boolean  lastButtonOn  = LOW;
boolean  currentButtonOn = LOW;
boolean  lastButtonOff = LOW;
boolean  currentButtonOff = LOW;
volatile int  buttonPinOn = 0;          //arduino 2   // the pin that the ON pushbutton is attached to
volatile int  buttonPinOff = 1;         //arduino 3   // the pin that the OFF pushbutton is attached to


void setup()              //start of the setup() function
                          //where is the code for setup() ?
boolean debounce1(boolean last)  //start of the debounce1() function
{
  boolean current = digitalRead(buttonPinOn);
  if (last != current);    //semi-colons on the end of if stops them working
}                          //is this really the end of the debounce1 function ?
{                          //what is this the start of ?
  delay(5);
  return current;
}
boolean debounce2(boolean last)
{
  boolean current = digitalRead(buttonPinOff);
  if (last != current);
}
{
  delay(5);
  return current;
}


{                              //this is the body of the setup() function
  pinMode(buttonPinOn, INPUT);
  pinMode(buttonPinOff, INPUT);

}

void loop(){
  currentButtonOn= debounce1(lastbuttonOn);   //wrong variable name
  currentButtonOff= debounce2(lastbuttonOff); //wrong variable name
  if (lastButtonOn==LOW&&currentButtonOn==HIGH);
  if (lastButtonOff==LOW&&currentButtonOff==HIGH);
  lastButtonOn= currentButtonOn;
  lastButtonOff= currentButtonOff;
}
Your code with amended so that it at least compiles
Code:
boolean  lastButtonOn  = LOW;
boolean  currentButtonOn = LOW;
boolean  lastButtonOff = LOW;
boolean  currentButtonOff = LOW;
volatile int  buttonPinOn = 0;          //arduino 2   // the pin that the ON pushbutton is attached to
volatile int  buttonPinOff = 1;         //arduino 3   // the pin that the OFF pushbutton is attached to

boolean debounce1(boolean last)  //start of the debounce1() function
{
  boolean current = digitalRead(buttonPinOn);
  if (last != current)   //removed semi colon
    //}                        //commented out
  {                          //start of code for if == true
    delay(5);
    return current;
  }                          //end of code for if == true
}                            //end of function

boolean debounce2(boolean last)
{
  boolean current = digitalRead(buttonPinOff);
  if (last != current)    //removed semi colon
    //}            //commented out
  {                //start of code for if == true
    delay(5);
    return current;
  }                //end of code for if == true
}                  //end of function

void setup()              //start of the setup() function
                          //now the code for setup()
{                              //this is the body of the setup() function
  pinMode(buttonPinOn, INPUT);
  pinMode(buttonPinOff, INPUT);
}

void loop(){
  currentButtonOn= debounce1(lastButtonOn);    //corrected variable name
  currentButtonOff= debounce2(lastButtonOff);  //corrected variable name
  if (lastButtonOn==LOW&&currentButtonOn==HIGH);
  if (lastButtonOff==LOW&&currentButtonOff==HIGH);
  lastButtonOn= currentButtonOn;
  lastButtonOff= currentButtonOff;
}
Pages: 1 ... 5 6 [7] 8 9 ... 234