Go Down

Topic: All I want to do is BEEP! to show that the program (Read 26906 times) previous topic - next topic

J.Smith

All I want to do is BEEP! to show that the program is running.
The code I downloaded from Amiga Playground is:

#define SPKR 4 //this is the digital pin that you plugged the red       wire into

void setup()
{
   pinMode(SPKR, OUTPUT); //set the speaker as output
}

void loop() //do this over and over
{
   digitalWrite(SPKR, HIGH); //turn the speaker on
   delay(500);                     //wait for half a second
   digitalWrite(SPKR, LOW); //turn the speaker off
   delay(500);                    //wait for half a second
}

It is weird, because this only gives me very LOW tones sounding like a cricket chirp! chirp! chirp!  I tried a diferent speaker Piezo and I also tried another program to verify the port to see if it was working. It plays Music on port 4 with the melody playing program. That might be ok to put on the robot, but I don't know how to stop it. It seems it either plays all or none.

This is a silly question, but I have tried all day to make this work.

I finally got control of my eyebrows, not total control , but enough to make them go UP when I run the little subroutine. So, now I will have to make them go also down at the right place in the program. The FUN part is when I have to use the sensors to make the Ping track the item when it sees it. That is going to be fun.  Wow!  I did all of this before on the boebot. But, the poor little basic stampII could not handle it. Everything worked as I told it to, but not fast enough to be practical. When I went to a BS2pe and a BSpx24 the code changed so much nothing worked. Same way with the propeller. I have been very satisfied with the ArduinoMega as far as speed so far.

I have checked and double checked and this just hasn't worked according to plan.

Thanks,

;)

TBAr

#1
Aug 09, 2009, 04:36 am Last Edit: Aug 09, 2009, 04:48 am by TBAr Reason: 1
The following UNTESTED code will generate a beep if you put it in the setup() part of a sketch.

Remove everything from the loop() function (but leave the empty loop() function there).

Code: [Select]

for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
 digitalWrite(SPKR, HIGH);
 delayMicroseconds(500);
  digitalWrite(SPKR, LOW);
  delayMicroseconds(500);
 }

Note the difference between your
   delay(500);
and the
   delayMicroseconds(500);
in the code above.

J.Smith

Thank You sooo much for your help.

God Bless!

:-)

pluggy

A very quick and dirty beep can be had via a PWM pin and analogueWrite.

eg analogWrite(beepPin, 128);
http://pluggy.is-a-geek.com/index.html


zooto68


J.Smith

#6
Aug 11, 2009, 03:31 pm Last Edit: Aug 11, 2009, 03:33 pm by J.Smith Reason: 1
did someone say AMIGA playground??  I had fun with the com. vic 20, then 64 then 128 then amiga500,1000,3000, and 4000 with the toasters. At that time NEWTEK was the BEST EVER.  They are still Great, but Paul Montgomery Died.   I Love the Amiga. It was my favorite computer next to the Mac with Leopard.

I have since solved the Beep problem with all of the kind help from this forum. It was a timing problem.

Go Up