Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 04:01:48 pm
it works now. thank you so much smiley
2  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 03:50:23 pm
Is this the right logic?

First step is to tell the arduino to read the status of pin 11..under the void loop.

digitalRead (11);

Then if its set to high I want it to activate the buzzer.

if (11,HIGH){
buzz(5, 2500, 500);
delay(1000);

The logic seems fine, I think I just dont know how to write it properly. Am I making a coding mistake?
3  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 03:40:24 pm
sorry i realized i posted the version of me seeing if changing the pin would do anything. Yea, id like it to read the pin, and if its on (HIGH) it will turn on the buzzing.
4  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 03:38:07 pm
1 sec let me truncate the specific code...

Code:
int ledPin = 11;

void setup()
{
//basic setup
{
pinMode(ledPin, OUTPUT);      // sets the digital pin as output
//set the pin modes
pinMode(5, OUTPUT); // set a pin for buzzer output
pinMode(11, OUTPUT); //used for the led

}
}

void loop() {
  
if (11,HIGH){
buzz(5, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 500 milliseconds
delay(1000); // wait a bit between buzzes
}
digitalWrite(ledPin, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin, LOW);    // sets the LED off
delay(1000);                  // waits for a second


}

void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to
  //// get the total number of cycles to produce
 for (long i=0; i < numCycles; i++){ // for the calculated length of time...
    digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait againf or the calculated delay value
  }
}
5  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 03:35:18 pm
ok im back. I set up a command...

if (11,HIGH){
buzz(5, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 500 milliseconds
delay(1000); // wait a bit between buzzes
}

but regardless of whether the pin is HIGH or LOW the buzzer will beep.

Is my if function wrong?
Thanks.
6  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 02:59:43 pm
haha yea. sorry about that. I'm still kind of new to the arduino scene and I have these fears that if i make a mistake something will catch fire...  If I run into any more problems I'll come back with a specific problem.
7  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 02:52:47 pm
----------ok so i figured out what was wrong. Thanks again guys.

My next question is how would I set the buzzer to react to a trigger. Whenever the servo rotates I'd like the buzzer to activate, and be able to turn off the buzzer based on another trigger.

If i type
if digitalwrite(11,HIGH);
buzz(5, 2500, 500);

Or something along that logic, will it work?
8  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 02:20:21 pm
thanks for the help guys. I blanked out

//potIn = analogRead(potPin); //read the position the potentiometer is at
//if the trigger value is 0 fill the hopper
//if(!trigger)

and it worked...I dont know why. Now i have to find a way to intergrate that to make the servo work lol.
9  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 02:11:02 pm
lol yea, I was afraid if I compartmentalize everything I would get lost.
10  Using Arduino / Programming Questions / Re: Not sure why im getting such a huge delay. on: April 02, 2013, 02:07:54 pm
yes
11  Using Arduino / Programming Questions / Not sure why im getting such a huge delay. on: April 02, 2013, 02:04:47 pm
Hi I'm trying to set a buzzer to buzz... I loaded this program
Code:
void setup() {
  pinMode(5, OUTPUT); // set a pin for buzzer output
}

void loop() {
  buzz(5, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 500 milliseconds
  delay(1000); // wait a bit between buzzes
}


void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to
  //// get the total number of cycles to produce
 for (long i=0; i < numCycles; i++){ // for the calculated length of time...
    digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait againf or the calculated delay value
  }
}

and it works fine, but when I transplanted it to another program, the delay between buzzes get prolonged... why?

here is the transplanted code.
Code:

#define fill 155 //the position in degrees to fill the hopper
#define empty 20 //the position in degrees to empty the hopper
#define potPin A0 //this is the pin (must be analog) that the middle of the potentiometer is connected to

#include <Servo.h> //this is a library used to control a servo (for more information see www.arduino.cc for more info)
 
//variables
Servo mainServo; //declare the main servo
int trigger = 0; //this is used to switch between fill and empty
int potIn = 0; //this is the data read from pin A0 (the potPin)
int count = 1; //used as a time muliplier


void setup()
{
//basic setup
mainServo.attach(3); //tell arduino which pin the servo is on (the white wire from the servo)
//set the pin modes
pinMode(4, OUTPUT); //used to output 5V or High to the potentiometer
pinMode(5, OUTPUT); // set a pin for buzzer output
pinMode(10, OUTPUT); //used for the led
pinMode(11, OUTPUT); //used for the led

digitalWrite(4, HIGH); //set pin 4 high
digitalWrite(10, LOW); //set pin 10 low
}


void loop() {
{
buzz(5, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 500 milliseconds
  delay(1000); // wait a bit between buzzes 

potIn = analogRead(potPin); //read the position the potentiometer is at
//if the trigger value is 0 fill the hopper
if(!trigger)
{
mainServo.write(fill);//move servo to fill position
//this is used to setup the delay
//count = 171 //uncomment this to set the max delay to 3 hours
//the delay below is calculated using potin (which can be 0-1024) as delayinseconds ~= 0 - 64 seconds
for(;count>=0;count--)
{
for(;potIn>0;potIn=potIn-20)
{
//this is to make the LED flash every 100+potIn miliseconds
digitalWrite(11,HIGH); //set led to on
delay(100+potIn);
digitalWrite(11,LOW); //set led to off
delay(100+potIn);
}
}
count = 1;
trigger = 1; //change trigger to 1 to setup empty
digitalWrite(11,LOW); //set led off
}
else if(trigger)
{
mainServo.write(empty); //set the servo to empty position
delay(1000); //delay while servo sets position
trigger = 0; //change trigger to 0 to setup fill
}
}

void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to
  //// get the total number of cycles to produce
 for (long i=0; i < numCycles; i++){ // for the calculated length of time...
    digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait againf or the calculated delay value
  }
}

Thanks guys
12  Using Arduino / Programming Questions / Re: I Keep getting errors when I try to upload on: October 17, 2012, 04:44:48 pm
thats the code with all my edits. the original code can be found here:

http://www.instructables.com/id/Environmental-Mushroom-Control-Arduino-Powered/?ALLSTEPS

or more specifically:

http://www.instructables.com/files/orig/FMK/3BR4/GAPURHM2/FMK3BR4GAPURHM2.tmp
13  Using Arduino / Programming Questions / Re: I Keep getting errors when I try to upload on: October 17, 2012, 12:58:10 pm
same problem with 25. Im pretty sure its a coding problem. I keep getting "Temp Trigger 1" flash o nthe screen so im gonna assume theres an error in this part of the code.

Code:
/** LCD Shield            */
serLCD lcd(13); // use both lines
char buf[5]; //used in conversion of int to char for lcd

int configure = 0; //use select as an on/off for configuring
int showReading = 0; //select which value to modify  0-3
int adc_key_in = 1024; //Start with -1 key value

int adc_key_val[5] = {
  100, 160, 360, 770, 800 }; //Analog values from Keys on keypad shield

/*
int adc_key_val[5] = {
 65, 218, 393, 601,1000};
 */
int NUM_KEYS = 5;
int key= -1;

char trigger_names[4][15] = {   
  "Temp Trigger 1",
  "Temp Trigger 2",
  "Humid Trigger",
  "C02 Trigger" };

/* Set up index value for storing values in eeprom*/
int k=0;
14  Using Arduino / Programming Questions / Re: I Keep getting errors when I try to upload on: October 17, 2012, 12:11:09 pm
Im using an arduino uno.
I replaced the value with 125. still same problem.
After the screen goes blank the words "Temp Trigger 1" very lightly (can barely see unless you focus) flash on screen.
15  Using Arduino / Programming Questions / Re: I Keep getting errors when I try to upload on: October 16, 2012, 07:55:20 pm
I'm so close!!! It works for 1 second! the information, data and setup all flashes on screen for about 1-2 seconds. After that the screen goes blank.
Pages: [1] 2 3