Show Posts
Pages: 1 ... 36 37 [38] 39 40 ... 102
556  Using Arduino / Programming Questions / Re: Problem with serial read and swiches? on: March 18, 2014, 11:02:44 pm
Hi there,

I am working on some code that reads incoming bytes from the serial RX pin on the arduino.
once it receives the correct byte it toggles a led on or off, however the problem i have is that i have a mom switch
hooked up (with a debounce schmitt trigger circuit etc) that i want it to do the same job of toggling the same led, yet they are clashing with each other and not sure how to get around it.
Keep a record of the state of pin 13 in a boolean variable so that you don't have to read the state of an output.
Code:
boolean ledState = 1;
void loop()...
if (Byte1 == 1){
       if (ledState ==0) // led on pin 13 is on
           digitalWrite(13, HIGH);
      else
           digitalWrite(13,LOW); // latches led high or low
      ledState = !ledState;  //flip the value of ledState
}

 //Then i have a switch on pin 3

if (digitalRead (3) == HIGH){ // Read mom switch debounce circuit on pin 3
      if (ledState == LOW)      //read led state
          digitalWrite(13, HIGH);
      else
          digitalWrite(13,LOW);
      ledState = !ledState; //flip the value of ledState
}
But that contracts to:
Code:
if (Byte1 == 1){
      digitalWrite(13, !ledState);
      ledState = !ledState;  //flip the value of ledState
}
 //Then i have a switch on pin 3

if (digitalRead (3) == HIGH){ // Read mom switch debounce circuit on pin 3
      digitalWrite(13, !ledstate);
      ledState = !ledState; //flip the value of ledState
}
and further contracts to:
Code:
if (Byte1 == 1 || digitalRead (3) == HIGH){ //Or condition
      digitalWrite(13, !ledState);
      ledState = !ledState;  //flip the value of ledState
}
557  Using Arduino / Programming Questions / Re: Variable Declaration Error? on: March 18, 2014, 10:12:27 pm
I have this problems figuring out the error that has come up in the variable declaration. I am modifying a program i found online but when i hit 'Verify' the error keeps on showing up. The error is 'expected initializer before int'
Here is the error:
Code:
//variables for tuning
int correctFrequency; //the correct frequency for the string being played
int Up //FOR THE OCTAVE INDICATORS
int Up2
int Up3
int Up4
int Down1
int Down2
int Down3
int Down4
Each of those lines needs a semicolon at the end.
558  Using Arduino / Programming Questions / Re: How to run a function for a specific interval, i.e. 10s? on: March 18, 2014, 12:31:57 am
I am working on code to ON the LED for 10 seconds after certain condition (x=false), but the code below runs infinitely. How should correct it? Thanks. I don't want to use delay() function as it stop the other functions running inside the loop.

Code:
void loop()
{
   if(x=false){
    TimerLighting = millis();
    if(millis()-TimerLighting <=10000){
      digitalWrite(LED,HIGH); 
      }
     else{
      digitalWrite(LED,LOW);   
     }
   }
}
You're setting TimerLighting = millis() each time through loop() and then immediately checking  if(millis()-TimerLighting <=10000). This will always be true! Just as looking at a clock every 5 minutes to see if an hour has passed since you last looked at the clock will always be false. TimerLighting = millis(); should be in setup() so that it only gets set once.
559  Using Arduino / Project Guidance / Re: First Arduino Project. Is it Possible and a good first build? Chicken Coop on: March 17, 2014, 11:07:08 pm
Certainly possible, but you should approach it in stages. Get the RTC and door opening/closing working first, then add the other parts, one at a time.
Quote
It seems pretty basic.  How do i learn how to code all this stuff.  Where do i begin to learn how to get this all up and going from a completely new perspective?
I suggest you start with a kit. These usually include a book for the beginner with some examples to work through. Working through all the examples will give you a basic understanding of the electronics and coding involved. Once you've done that, you're not on your own, as this forum is here to help you.
560  Community / Bar Sport / Re: Normal English phrase embarrassing in the US on: March 16, 2014, 11:02:49 pm
I know, as a tourist in England, never to refer to my utility belt as a "fanny pack"
And a bathroom does not always have a toilet in it.
561  Using Arduino / Programming Questions / Re: Simple Switching Sequences on: March 16, 2014, 08:16:36 pm
What UKHeliBob said, and make sure you debounce your button.
562  Community / Bar Sport / Re: Old electric meter housing on: March 15, 2014, 09:42:54 pm
whats your next project? a digital power meter?
He's going to get it to run backwards and use it as a countdown timer.   smiley-cool
563  Using Arduino / Project Guidance / Re: Movable Bridge Traffic Lights on: March 15, 2014, 08:07:24 pm
Code:
void loop()
{
  Serial.println(Count);  
  Serial.println(Count);
  
  if(Count == 0)
  {
    digitalWrite(CarLED, HIGH);
    digitalWrite(BoatLED, HIGH);
    Count = checkcount();
    delay(1000);
    Serial.println(Count);
    digitalWrite(BoatLED, LOW);

Here you set BoatLED LOW, but a few microseconds later,
in the next iteration of loop(), you set it high again.
It does go off, but you don't see it, as it's off for such a short time.
  } 
564  Using Arduino / Programming Questions / Re: While loop not behaving as expected! on: March 14, 2014, 10:25:13 pm
While we are letting people onto the cars, the Arduino will be tied up, hence the need for an interrupt.
Tied up doing what?
Quote
I am in the process of writing a flow chart to describe the process and it is getting more complicated than I initially thought it would be.
That's almost always the case!  smiley-eek
565  Using Arduino / General Electronics / Re: Can someone please tell me the identity of this 7 segment display [Sorted] on: March 13, 2014, 10:54:43 pm
Hi, can you supply a picture of it , possibly with a ruler in the pic.

Thanks Tom.... smiley
I'll try to do that tomorrow.
566  Using Arduino / General Electronics / Re: Can someone please tell me the identity of this 7 segment display [Sorted] on: March 13, 2014, 10:51:23 pm
Ha, I Googled "Fairchild ND10402-531", and it came up with just 1 result!, this page. smiley-lol
I told you there was nothing on google...
Quote
Runaway Pancake made a good suggestion, but if your multimeter's ohms range doesn't provide enough voltage and current to  dimmly light the individual segments, then you could use a couple of AA cells and a series resistor to "investigate" the connections.  That voltage should not cause any damage if you have a reversed connection.
Yep. That's exactly what I did, using a couple of slightly discharged Ni-MH cells (2 * 1.2V) and found that, as I suspected, the centre leg is the common (-ve) one. Now all I need is to find a socket for it or a small piece of stripboard or protoboard with a 1mm pitch!  smiley-eek-blue
567  Using Arduino / Programming Questions / Re: Interrupts to change LED color out of continues function on: March 13, 2014, 10:12:03 pm
I don't see any interrupts, and I don't see any setup or loop either.
I see no need for interrupts. The Blink Without Delay example in the IDE will show you how to do it.
568  Using Arduino / Programming Questions / Re: Controlling servo position with 2 switches, but servo shakes out of position on: March 13, 2014, 09:55:46 pm
Where, in your code, are you keeping track of the current servo position?
569  Using Arduino / Programming Questions / Re: Stepper Motor Programming on: March 13, 2014, 09:39:54 pm
Here is the code I have so far.
You need a flag to keep track of when the door is open and when it is closed.
Code:
...
boolean doorOpen = 0;
 //Assumes the door is closed at start. If not, doorOpen = 1;
void setup() {
 Serial.begin(9600);
 // set the PWM and brake pins so that the direction pins 
// can be used to control the motor:
pinMode(pwmA, OUTPUT);
 pinMode(pwmB, OUTPUT);
 pinMode(brakeA, OUTPUT);
 pinMode(brakeB, OUTPUT);
 pinMode(motion_1, INPUT);
 digitalWrite(pwmA, HIGH);
 digitalWrite(pwmB, HIGH);
 digitalWrite(brakeA, LOW);
 digitalWrite(brakeB, LOW);

 
 // initialize the serial port:
 Serial.begin(9600);
 // set the motor speed (for multiple steps only):
 myStepper.setSpeed(80);
}
void loop()
{
if( digitalRead(motion_1)== HIGH && doorOpen == 0){
//PIR detecting and door not open
  myStepper.step(200);  //adjust to do number of steps to open door
  doorOpen =1;  //remember that the door is open
   }
if( digitalRead(motion_1)==LOW&& doorOpen == 1){
//PIR NOT detecting and door open 
  myStepper.step(-200);   //adjust to do number of steps to close door
   doorOpen =0;  //remember that the door is closed
   }
}
Please post your code between code tags, the # key above the input box.
570  Using Arduino / Programming Questions / Re: While loop not behaving as expected! on: March 13, 2014, 08:57:21 pm
pretty sure the line
while ((Switch0 == LOW)  || (Switch3 == LOW)); {
should be
while ((Switch0 == LOW)  || (Switch3 == LOW)) {

Basically removed the apostrophe, pretty sure that'll fix your problem
It's the semicolon that he needs to remove. There's no apostrophe there.
Pages: 1 ... 36 37 [38] 39 40 ... 102