0

Help needed please Gemma buzzer on delay
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Help needed please Gemma buzzer on delay

by waterdude on Mon May 08, 2017 5:58 am

Hello everyone,
I am very new to this and can't yet code so I'm looking for a jumpstart :)

I have a gemma and neopixel ring and a buzzer that I want to build a circuit with.

What I want it to do is after a closed push switch is opened I want both the buzzer to chirp/buzz and the neopixel ring to show a rotating ring of red pixels after a certain time (60 seconds).

I want it to continue sounding the buzzer and rotating the neopixel ring until the switch is closed again.

Any help would be greatly appreciated :)

Thanks,
Stu.

waterdude
 
Posts: 5
Joined: Fri May 05, 2017 4:59 am

Re: Help needed please Gemma buzzer on delay

by adafruit_support_mike on Wed May 10, 2017 2:00 am

If you're just getting started with programmable hardware, take a look at our Learn Arduino series of tutorials:

https://learn.adafruit.com/adafruit-ard ... on-1-blink

That will help you get familiar with the pieces and process, and most of the information carries over to the Gemma without too much trouble.

Controlling things with a pushbutton starts around tutorial 6, and there are several examples that use control buttons after that. Start with the basics, just lighting an LED in reponse to the button input, then once you know that works the way you want, you can go on to controlling a buzzer and NeoPixel ring.

adafruit_support_mike
 
Posts: 43132
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help needed please Gemma buzzer on delay

by waterdude on Wed May 10, 2017 7:55 am

Hey thanks Mike ;)

waterdude
 
Posts: 5
Joined: Fri May 05, 2017 4:59 am

Re: Help needed please Gemma buzzer on delay

by waterdude on Wed May 10, 2017 8:00 am

So this as far as i have got now. Something is not right though as it's not working

Screen Shot 2017-05-10 at 12.55.06.png
Screen Shot 2017-05-10 at 12.55.06.png (660.68 KiB) Viewed 196 times


Code: Select all | TOGGLE FULL SIZE
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN 1

//Switch will be connected to Pin-0 and Buzzer to Pin-2 of Gemma board
#define Switch 0
#define Buzz 2
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 12

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void Start_Ring_Buz();// declaring prototype

//int delayval = 500; // delay for half a second

void setup()
{
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket

// End of trinket special code

pinMode(Switch,INPUT);
pinMode(Buzz,OUTPUT);
//Switch=LOW;
//Buzz=LOW;

pixels.begin(); // This initializes the NeoPixel library.
}
//------------------------------------------------------------
void loop()
{
if (Switch)
{
Wait(5000);//wait for 53 seconds
Start_Ring_Buz();
}
else if (!Switch)
{
digitalWrite(Buzz,LOW);//Turn OFF Buzzer O/P Transistor
Stop_Ringing();
}
else ;
}

//------------------------------------------------------------


void Start_Ring_Buz(void)
{

digitalWrite(Buzz,HIGH);//Turn ON Buzzer O/P Transistor

// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<NUMPIXELS;i++)
{
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(255,0,0)); // Full bright Red color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500); // Delay for a period of time (in milliseconds).
}

digitalWrite(Buzz,LOW);//Turn OFF Buzzer O/P Transistor

for(int i=0;i<NUMPIXELS;i++)
{
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Fully Off All color..
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500); // Delay for a period of time (in milliseconds).
}
digitalWrite(Buzz,HIGH);//Turn ON Buzzer O/P Transistor
}

void Stop_Ringing(void)
{
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(12, pixels.Color(0,0,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
}

void Wait(unsigned int x)
{

for (int i=0; i<=x; i++)
delay(1000);
}

waterdude
 
Posts: 5
Joined: Fri May 05, 2017 4:59 am

Re: Help needed please Gemma buzzer on delay

by adafruit_support_mike on Thu May 11, 2017 1:34 am

What's the last thing that works as expected before the first thing that doesn't do what you expect?

adafruit_support_mike
 
Posts: 43132
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help needed please Gemma buzzer on delay

by waterdude on Thu May 18, 2017 6:33 am

Woo Hoo!! I got it working!!! Now i am trying to work how to make the buzzer sort of chirp instead of buzz.

waterdude
 
Posts: 5
Joined: Fri May 05, 2017 4:59 am

Re: Help needed please Gemma buzzer on delay

by adafruit_support_mike on Thu May 18, 2017 11:40 pm

Glad to hear it's working for you.

A chirp usually involves an increasing frequency:

Code: Select all | TOGGLE FULL SIZE
#define BUZZER  5

void setup() {
    pinMode( 5, OUTPUT );
}

void loop() {
    beep( 2000, 20 );
    beep( 5000, 30 );
    delay( 1000 );
}

//  parameter 'f' is the frequency in Hertz
//  parameter 't' is how long the beep should last in milliseconds

void beep ( uint32_t f, int t ) {
    uint32_t now = millis();
    int tau = 500000 / f;
   
    while (( millis() - now ) < t ) {
        digitalWrite( BUZZER, HIGH );
        delayMicroseconds( tau );
        digitalWrite( BUZZER, LOW );
        delayMicroseconds( tau );
    }
}

adafruit_support_mike
 
Posts: 43132
Joined: Thu Feb 11, 2010 2:51 pm

Re: Help needed please Gemma buzzer on delay

by waterdude on Fri May 19, 2017 7:55 am

Whoop, chirp, beep! Cheers Mike.

waterdude
 
Posts: 5
Joined: Fri May 05, 2017 4:59 am

Please be positive and constructive with your questions and comments.