Show Posts
Pages: 1 2 [3] 4 5 ... 226
31  Using Arduino / Programming Questions / Re: Have arduino code respond to "down press" of button. on: July 23, 2014, 06:51:19 pm
You're looking for a transition from either HIGH to LOW or LOW to HIGH, depending on how the switch it wired, which correspond to the push down and release actions. That's accomplished with this check:

Code:
monoButtonStateReset != monoButtonState

To see which one it is, you simply need to check if the current state is HIGH, indicating a LOW to HIGH transition, or LOW, indicating a HIGH to LOW transition.

Change this
Code:
monoButtonState == 1

to either

Code:
monoButtonState == HIGH

or

Code:
monoButtonState == LOW

depending on your wiring.
32  Using Arduino / Programming Questions / Re: How to split an incoming serial into int on: July 23, 2014, 06:35:42 pm
I'm not quite sure what you mean by synchronize

Let's say I wanted to tell you what the lottery numbers were for the last 50 years. Say its 5 numbers per lottery. I start talking, and you start writing:

120, 12, 76, 23, 64, 23, 195, 123, 634, 136

At this point, since you know it's 5 numbers per lottery, and you started listening before I started talking, so you know that the first 5 numbers go to the first lottery, and the next 5 go to the next lottery. You write it down as such:

Lottery #1: 120, 12, 76, 23, 64,
Lottery #2: 23, 195, 123, 634, 136

But what happens if you don't start listening until after I've spoken the first two numbers. What you hear, instead, is

 76, 23, 64, 23, 195, 123, 634, 136, 1, 99

So you write it down as such

Lottery #1: 76, 23, 64, 23, 195,
Lottery #2: 123, 634, 136, 1, 99

That's what is meant by synchronization; you need a way for the receiver to know where in the data set the sender is when the receiver starts listening. How you do this will depend on the sender. Does it send a delimited character like a new line? Is there a temporal break in time between sets of data? Could the value tell you something about its placement in the set?
33  Using Arduino / Programming Questions / Re: Looping LED patterns and using a button to break the loop on: July 22, 2014, 10:16:41 am
Do you have an example of this?  My coding experience is mostly combining code

Blink Without Delay
34  Using Arduino / Programming Questions / Re: Save Strings on: July 22, 2014, 10:10:16 am
why it stop saving the Strings

What does that even mean? You have to describe your problem much better than an ambiguous word like "save"
35  Using Arduino / Programming Questions / Re: Problem with the Serial.read() command on: July 22, 2014, 10:08:13 am
Code:
void loop ()

 
  val = Serial.read();
 
if(val == 'a')
{
 digitalWrite(led, HIGH);
 Serial.write("led ON");
}
val = Serial.read();
  if(val == 'a')
  {
  digitalWrite(led, LOW);
Serial.write("led OFF");
}
  }
 

Loop runs very quickly, and Serial.read() doesn't stop and wait until there is something in the buffer, so you're leaving it up to change as to which Serial.read actually pulls the character out. Rarely, should there be more than one serial read per UART in a given sketch, this isn't one of those times.
36  Using Arduino / Programming Questions / Re: Delay a pin state after event on: July 18, 2014, 03:33:30 pm
All that snippet does is tell you how long the button was pushed down for. You need some type of structure like this:

Code:
if (someEventOccurs)
{
   // turn a relay on
   relayTurnOnTime = millis();
}

if (millis() - relayTurnOnTime > 1000)
{
   // turn off relay
}
37  Using Arduino / Programming Questions / Re: Invalid cast from type ‘String’ to type ‘int’ on: July 18, 2014, 02:22:04 pm
Code:
        pos1=String(chaineReception[0]).toInt()*100 + String(chaineReception[1]).toInt()*10 + String(chaineReception[2]).toInt();

toInt() can handle more than a single character String. The above link has an example of it doing just that.
38  Using Arduino / Programming Questions / Re: Using packed binary data from pc serial on: July 18, 2014, 02:20:30 pm
You just reposted what you said in your first post, instead of expanding on it given the questions asked. I didn't ask where the data was coming from, I ask what was sending it. PCs don't send it. Programs on the PC, do. If there is no way to differentiate when a packet starts or ends (either through markers or time, then you're in a bit of a pickle, because you need some way to differentiate the streams, else you run into a great amount of issues with synchronization.
39  Using Arduino / Programming Questions / Re: Delay a pin state after event on: July 18, 2014, 01:11:17 pm
Start by identifying the time at which the signal is received. Record that time with millis. Then periodically check to see how long it has been since the event was recorded, and turn off the relay when that time comes.
40  Using Arduino / Programming Questions / Re: Using packed binary data from pc serial on: July 18, 2014, 01:10:07 pm
Any help with code, hints, or links would be HUGE!!!

It's still unclear what you are accomplish. What's sending the data? Is it sending anything to indicate when the data has "started" or "stopped"? Is it sending the same length every time?
41  Using Arduino / Programming Questions / Re: Invalid cast from type ‘String’ to type ‘int’ on: July 18, 2014, 01:04:11 pm
why I can't convert String to int ?

You can if you do it properly.

http://arduino.cc/en/Reference/StringObject

Look at the available functions.
42  Using Arduino / Programming Questions / Re: myFirstLibrary, miles out? on: July 18, 2014, 10:39:09 am
Don't cross-post.
43  Using Arduino / Programming Questions / Re: Serial Monitor -> GUI on: July 18, 2014, 10:33:55 am
Not by using the Serial Monitor; you'll need a different terminal program.
44  Using Arduino / Programming Questions / Re: Merge servo and relay sketches on: July 18, 2014, 10:23:08 am
How to use this forum - please read.

#7

Code:
// read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }}

So the entire purpose of this function is to just set the LED to the state of the button? This could be done much easier by wiring it up that way, but if you insist on using software, then the entire function can be boiled down to a single line.

Code:
digitalWrite(ledPin, digitalRead(buttonPin));

I would also not recommend naming a function "pumprelay" if all it is doing it controlling an LED.

Code:
// process times
  now = millis();
  endtime = now + FEEDINGDELAY;
  
  while(now < endtime) {
   myservo.write(80);
   Serial.print("soon... ");
   Serial.println(endtime-now);
   delay(20000);
   now = millis();  
  }

What exactly is the point of endtime here? You set it to three hundred milliseconds after the current time, then wait 20 seconds. May as well just remove the while structure, because it's not doing anything for you.

Previously the pump relay code would only detect change or be implemented when the servo was operating. Is this solved by the way I have placed the void pumprelay function?

Your pumprelay function has zero coupling with the servo. In other words, they don't affect each other (with the exception being the delays cause the pumprelay function to be called infrequently). Is that what you're going for?
45  Using Arduino / Project Guidance / Re: run a buzzer after 10 cycles of running program on: July 18, 2014, 10:06:06 am
Code:
   if((signal1 == HIGH && signal2 == HIGH) && (signal3 == HIGH && signal4 == HIGH))

signal1, 2, 3, etc. Are pin numbers. You shouldn't be comparing pin numbers to states. You should be using digitalRead to get the state of a digital pin, then compare the results to HIGH or LOW.
Pages: 1 2 [3] 4 5 ... 226