#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
#include <SoftwareSerial.h>
Adafruit_SSD1306 display(OLED_RESET);
SoftwareSerial BTserial(0,1);
int analogInput = A0;
char company[]="ABCDEFG Technologies";
char unit[]="dB";
const int sampleWindow = 50;
unsigned int sample;
const int noise=A1;
void setup(){
BTserial.begin(9600);
Serial.begin(9600);
pinMode(analogInput, INPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop(){
unsigned long startMillis = millis();
unsigned int PeaktoPeak = 0;
unsigned int SignalMax = 0;
unsigned int SignalMin = 1024;
while ( millis() - startMillis < sampleWindow ){
sample = analogRead(analogInput);
if (sample < 1024) {
if (sample > SignalMax){
SignalMax = sample;
}
else if (sample < SignalMin){
SignalMin = sample;
}
}
}
PeaktoPeak = SignalMax - SignalMin;
float MeterValue = ( PeaktoPeak * 3.3 /675) * 100;
int change = map(MeterValue, 0, 1023, 0, 255);
analogWrite(noise, change);
Serial.println(MeterValue);
BTserial.println(MeterValue);
BTserial.println(company);
BTserial.println(unit);
char temp_buff[5];
char temp_disp_buff[11] = "Sound:";
dtostrf(a,2,1,temp_buff);
strcat(temp_disp_buff,temp_buff);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(temp_disp_buff);
display.display();
delay(2000);
}
Hi,
I'm doing project in digtal sound sensor MAX 9814 and sending 32byte data to android apk via bluetooth. I need to more specific in byte allocation because i'm sending three type of data One is Company name( char type), second sensor data (float type) and sound unit dB( char type). So need to allocate separate byte location for three data. Kindly help me to allocate separate byte location data with code.
Total Data to transfer = 0 to 256 bytes
Company name: ABCDEFGH Technologies(24bytes)
Decibel Value: 120.00(5bytes)
Decibel Unit: dB(2bytes)
for example:
0-24bytes : Company name(ABCDEFGH Technologies)
25-30bytes: Decibel Value(Float value-123.23)
31-32bytes : Unit name(dB)