So I have a working project with Arduino Uno. I now want to migrate it to the Beetle BlunoThe bluno beetle. I tried running the code on the Beetle and it does work. I cannot seem to get the Bluetooth to work though. The code is below:
#include <Bounce2.h>
#include <SoftwareSerial.h>
//#include <Wire.h>
//SoftwareSerial bluetooth_port(10, 11);
// Connect each button with one connection
// to GND and the other to a digital pin.
const byte buttonPinBLE1 = 2;
const byte buttonPinBLE2 = 3;
class Button{
private:
byte m_buttonPin;
byte m_counter = 0;
unsigned long m_buttonPressTimeout;
unsigned long m_previousMillis;
public:
Button(byte buttonPin):
m_buttonPin(buttonPin),
m_counter(0),
m_buttonPressTimeout(1500), // Button press timeout in ms.
m_previousMillis(0){}
void Update(){
if(m_counter > 0 && millis() - m_previousMillis >= m_buttonPressTimeout)
{
//Serial.print("Count from Update() just before it's reset to 0 = ");
Serial.println(GetCounter());
m_counter = 0;
}
}
void IncrementCounter(){
m_counter++;
if(m_counter > 4){m_counter = 4;}
if(m_counter == 1)
{
m_previousMillis = millis();
}
}
friend void IncrementCounter(Button&);
void IncrementCounter(Button&){
IncrementCounter();
}
byte GetCounter(){
return m_counter;
}
};
Bounce buttonOneDebouncer = Bounce();
Bounce buttonTwoDebouncer = Bounce();
Button ButtonOne(buttonPinBLE1);
Button ButtonTwo(buttonPinBLE2);
void setup(){
//Serial.begin(9600);
Serial.begin(115200);
pinMode(buttonPinBLE1, INPUT_PULLUP);
pinMode(buttonPinBLE2, INPUT_PULLUP);
buttonOneDebouncer.attach(buttonPinBLE1);
buttonTwoDebouncer.attach(buttonPinBLE2);
buttonOneDebouncer.interval(25);
buttonTwoDebouncer.interval(25);
}
void loop(){
// Call the Update function as fast as possible.
ButtonOne.Update();
ButtonTwo.Update();
// Button one pressed.
if(buttonOneDebouncer.update()){
if(buttonOneDebouncer.fell()){
if(digitalRead(buttonPinBLE2) == 0){
ButtonOne.IncrementCounter();
}
}
}
// Button two pressed.
if(buttonTwoDebouncer.update()){
if(buttonTwoDebouncer.fell()){
if(digitalRead(buttonPinBLE1) == 0){
ButtonOne.IncrementCounter(ButtonTwo);
}
}
}
if(digitalRead(buttonPinBLE1) == 0 && (digitalRead(buttonPinBLE2) == 0))
{
Serial.println("9");
}
}
Does anyone know how I can get the device to communicate with my computer via Bluetooth? I have no experience with the Beetle and I cannot seem to find much help online.
user19964user19964
asked Jan 15, 2020 at 22:26
-
Comments are not for extended discussion; this conversation has been moved to chat.VE7JRO– VE7JRO2020年01月17日 14:45:11 +00:00Commented Jan 17, 2020 at 14:45
-
@VE7JRO Hello. You helped me with the single tap, double tap question (arduino.stackexchange.com/questions/69897/…). Thank you so much for that once more. However, it isn't accurate and sometimes if i press the buttons once, it outputs a 2, sometimes it outputs a 4 when i press it twice. Do you know how I can fix this issue?user19964– user199642020年01月19日 01:06:41 +00:00Commented Jan 19, 2020 at 1:06
-
The original code I provided in the linked Q+A worked perfectly on a Arduino Uno. The sketch you are using in this question is different. I do not have a Beetle Bluno to test with, so I'm sorry, but I can't help you. If I can't test the sketch on the "same" hardware, then I'm just guessing, not answering.VE7JRO– VE7JRO2020年01月19日 01:28:03 +00:00Commented Jan 19, 2020 at 1:28
-
@VE7JRO the code I am using is on an Arduino Uno...it isn't working accurately for some reason on my side. I haven't started using the Beetle as yet so still testing on the Arduino Unouser19964– user199642020年01月19日 03:04:04 +00:00Commented Jan 19, 2020 at 3:04
lang-cpp