| Arduino Forum ::  Members :: boguz
 Show Posts Pages: [1] 2 3 ... 15
 1 Using Arduino / Programming Questions / Re: Hall Effect Speed and Distance Sensor Code on: April 20, 2014, 01:44:58 pm and for the speed you can also calculate it with a simple equation, something like:Speed = Distance / TimeSo if you know the circumference of the wheel and you masure how long it took it to make one turn, then you can also calculate the speed and display it on your lcd.
 2 Using Arduino / Programming Questions / Re: Hall Effect Speed and Distance Sensor Code on: April 20, 2014, 08:50:51 am if you have one magnet on the wheel and the sensor on the frame, each time the magnet passes the wheel you will have traveled the same distance as the circumference of your wheel.
 3 Using Arduino / Programming Questions / Re: Toggle between two modes or tasks on: April 19, 2014, 06:21:33 am when you press the button set the buzzer to buzz and save the time (using the millis() ) into a variable, called maybe something like buzzBegin.Then on the loop() check if your interval (1 second) as passed, something likeCode:if(millis() - buzzBegin >= interval) {   // stop your buzzer}this will help you avoid the use of the delay() function.
 4 Using Arduino / Programming Questions / Re: "Cutting off" circuit with 2 momentary switches on: April 19, 2014, 05:58:20 am was it something like this that you were looking for?Code:/*CIRCUIT:   * led to Arduino pin 4   * button1 to Arduino pin 8   * button2 to Arduino pin 9      (using a 10k pull-up resistor for both buttons)*/// VARIABLESint led = 4;boolean ledState = LOW;long ledStart;int interval = 2000;int but1 = 8;int but1State;int lastBut1State = HIGH;int but2 = 9;int but2State;int lastBut2State = HIGH;void setup() {  pinMode(led,OUTPUT);  pinMode(but1,INPUT);  pinMode(but2,INPUT);}void loop() {  // read buttons  but1State = digitalRead(but1);  but2State = digitalRead(but2);  // if button1 is pressed  if(but1State != lastBut1State && but1State == LOW) {    ledState = HIGH;      // set led state to HIGH    ledStart = millis();  // save starting time  }  // if button2 is pressed  if(but2State != lastBut2State && but2State == LOW) {    ledState = LOW;      // set led state to LOW  }  // check if 2 second have passed since led was turned on  if(millis() - ledStart >= interval){    ledState = LOW;      // set led state to LOW  }    digitalWrite(led,ledState);  // write the ledState    // update lastButton variables  lastBut1State = but1State;  lastBut2State = but2State;}i didn't try it, but give it a go and make any changes you need.as you can see i am not using the delay() function. i am using a very useful technic to see if a set amount of time as gone by which you can learn how to use here:http://arduino.cc/en/Tutorial/BlinkWithoutDelayGood lock!=)
 5 Using Arduino / Programming Questions / Re: if else or switch case? on: April 19, 2014, 02:29:01 am i would imagine that with so many if statements things would be better with a nicelly organized switch case... but i don't really have an explanation for that. it is just intuition, or something... But a quick search here in the forum took me to another thread with has a good amount of interesting information about this subject:http://forum.arduino.cc/index.php/topic,44519.0.htmlYou can read though it, but i think in the end they found out that actually if statements were smaller and faster on Arduino....but i have to tell you that i didn't read it whole, i just "jumped over it". I need to go back some other time with a bit more time!Would love to see to what conclusion you come. I have often thought about this also...
 6 Using Arduino / Programming Questions / Re: Toggle between two modes or tasks on: April 19, 2014, 02:20:19 am you are missing an opening curly bracket " {" after this line:Code:if(currState != prevState)and then you also need to add one more to the end of the void loop.i think also that maybe you should change this line:Code:prevState = currState;to a different place. Where you have it now, it is just working if the button is pressed. But you also want it to update the prevState on each pass, even if the button isn't pressed.So maybe something like this would work:Code:const int swPin = 2;const int ledRd = 9;const int ledGn = 8;int prevState = HIGH;int currState;byte mode = 0;void setup() {  pinMode(swPin, INPUT_PULLUP);  pinMode(ledGn, OUTPUT);  pinMode(ledRd, OUTPUT);}void loop() {  int currState = digitalRead(swPin);  if(currState != prevState) {    if(currState == LOW) {      mode = !mode; // Toggle mode      digitalWrite(ledRd, HIGH);      digitalWrite(ledGn, LOW);    }    else {      digitalWrite(ledRd, LOW);      digitalWrite(ledGn, HIGH);    }  }  prevState = currState;}
 7 Using Arduino / Programming Questions / Re: Serial.print() on: April 18, 2014, 03:04:42 pm you can alway try something likeCode:void setup() {   Serial.begin(9600);}void loop() {   Serial.println("WORKING!!!");}just to check that everything is in order...
 8 Using Arduino / Programming Questions / Re: Serial.print() on: April 18, 2014, 02:01:25 pm i think what they mean is that we can maybe help you further if you post the code you are using (using the CODE tags!)
 9 Using Arduino / Programming Questions / Re: Where am I going wrong with the no delay method? on: April 18, 2014, 11:24:24 am Quote from: GoForSmoke on April 18, 2014, 11:10:32 amYou do know that min and max use the same basic code if not more?you think that mapping the value of that analogRead would use more code?i meant something like this:Code:int interval = map(analogRead(0), 0, 1023, 5, 255);the "5" and "255" could easily be replaced by any values he wishes to use as minimum and maximum Interval times.
 10 Using Arduino / Programming Questions / Re: Expected Initializer before 'int' Error on: April 18, 2014, 11:13:10 am very often it is just that we forgot a ";" at the end of a line...but in your case i think it is because you often have two words as a variable name, something like:Code:int Red Pin 9;this doesn't work, you need to have a variable name in just one word, something like:Code:int redPin = 9;correct all those variable names and check if it works better...what is thisCode:{  for(int i=0;i< 3;i++);  {    pinMode (ledDigitalOne[i],INPUT) ;//SET THE RGB LED PINS AS OUTPUTS  }  Serial.begin(9600); // start the serial connection with the battery}between your setup() and your loop()? Is it working like you intended it? It seems you have code outside from any functions. It maybe be from the formatting, but maybe you can also check that out...(ah, and CMD+T auto formats your code...       )Why are you using Serial.begin() twice?Good luck!=)
 11 Using Arduino / Programming Questions / Re: Where am I going wrong with the no delay method? on: April 18, 2014, 11:06:12 am in your void flash, instead ofCode:interval = analogRead(0)/10; //read pot value, divide by 10 to reduce range of flash sweep speed  if (interval <5) // delays of less that 5 create too fast of a flash sweep. Set to minimum of 5  {    interval = 5;  }you could maybe map the value, like this you can easily control it's min and max values. No need for that if statement.on your code there are things like this:Code:if (ledState = LOW)but i imagine you wantCode:if (ledState == LOW)== is the comparison operator. it is kind of like "is it equal to?"= is something different. it is an assignment operator.  Makes the left variable equal to the right one.The idea behind the BlinkWithoutDelay is quite simple, but i remember it also took me some time to understand it.The basic idea is that for example instead of a delay(100) (which would "pause" the whole Arduino sketch for 100 miliseconds and not allow for anything to happen in this period) we can use the millis() function to see if a predetermind amount of time as gone by.So the easiest way to change your original sketch (which works for you) would be to just replace those delay() with that millis() technic.With that first code you posted, the one using delay(), was it actually working like you wanted? Or was it just not giving you any errors?Well, just a couple of ideas...