Topic: controlling a buzzer with remotexy
Hi, Im working on a circuit that I can use to help me find lost belongings. It has a led and a piezo buzzer, but I'm unable to get the buzzer to function properly. I have 2 switches on remotexy one to turn on a led the other to make the piezo buzzer play a siren sound. Im able to get the buzzer to start playing the sound but then it won't stop. Does anyone know how I can get the buzzer to turn off when I switch it off not the remotexy app? I also want to get the led to flash in a sequence though similar to the buzzer I can't figure out how to get it to work.
here is my current code.
/*
-- AllAround --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 3.1.8 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.11.1 or later version;
- for iOS 1.9.1 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 9600
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 130 bytes
{ 255,3,0,2,0,123,0,16,223,2,2,1,4,18,22,11,7,25,22,11,
224,26,31,31,79,78,0,79,70,70,0,129,0,35,5,27,6,18,10,18,
6,17,65,108,108,32,65,114,111,117,110,100,0,2,1,72,19,22,11,7,
58,22,11,224,26,31,31,79,78,0,79,70,70,0,69,0,45,32,10,10,
13,41,10,10,1,4,16,41,21,18,7,45,24,10,45,2,26,129,0,12,
14,6,3,14,20,8,4,24,76,69,68,0,129,0,78,15,10,3,12,53,
13,4,8,66,117,122,122,101,114,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t LED; // =1 if switch ON and =0 if OFF
uint8_t Buzzer; // =1 if switch ON and =0 if OFF
int8_t slider_1; // =0..100 slider position
// output variables
int16_t sound_1; // =0 no sound, else ID of sound, =1001 for example, look sound list in app
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_LED 13
#define PIN_BUZZER 8
void setup()
{
RemoteXY_Init ();
pinMode (PIN_LED, OUTPUT);
pinMode (PIN_BUZZER, OUTPUT);
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_LED, (RemoteXY.LED==0)?LOW:HIGH);
digitalRead(PIN_BUZZER, (RemoteXY.Buzzer==0)?LOW:HIGH);
if (digitalRead(8) == HIGH) {
digitalWrite(PIN_BUZZER, HIGH);
//siren going up
for (int frequency=650; frequency<900; frequency++) {
tone(8, frequency);
delay(10);
}
digitalWrite(PIN_BUZZER, LOW);
// siren going down
for (int frequency=900; frequency>=650; frequency--) {
tone(8, frequency);
delay(10);
}
}
else {
digitalWrite(PIN_BUZZER,0); //If the switch isn’t pressed, buzzer off.
}
delay(10); //reading delay
}
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay()