So , we have been trying this code for a while all the function are getting called except amonia. We have also tried it by making the function parameterized but it is still not working
here is the code:
#include <AHT10.h>
#include <avr/wdt.h>
#include <EEPROM.h>
#include <SPI.h>
#include <Wire.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <JQ6500_Serial.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <stdint.h>
#define OLED_RESET 9//4
uint8_t readStatus = 0;
JQ6500_Serial mp3(2,3);//RX, TX
AHT10 myAHT10(AHT10_ADDRESS_0X38);
Adafruit_SSD1306 display(OLED_RESET);
int x=0;
int y = 0;
int a,b;// b is used as a counter to run audio ackowledgement
int d1,d2,d3,o,t,h,gen; //digit1, digit2, digit3,once,tens,hundred,general purpose
int dly;
float humidity;
int bat;
int co,nh3,no2;
float no2f = 0.0;
float batf=0.0;
float gas=0.0;
float avg=0.0;
volatile float tempe,humi;
int rec;
const int buz = 9;
const int LD1 = 10;
const int LD2 = 11;
const int LD3 = 12;
uint32_t delayMS;
void setup() {
// put your setup code here, to run once:
pinMode(buz, OUTPUT);
pinMode(LD1, OUTPUT);
pinMode(LD2, OUTPUT);
pinMode(LD3, OUTPUT);
digitalWrite(LD1, LOW);
digitalWrite(LD2, LOW);
digitalWrite(LD3, LOW);
digitalWrite(buz, LOW);
delay(100);
digitalWrite(LD1, HIGH);
digitalWrite(buz, HIGH);
delay(100);
digitalWrite(LD2, HIGH);
digitalWrite(buz, LOW);
delay(100);
digitalWrite(LD3, HIGH);
delay(100);
digitalWrite(LD1, LOW);
digitalWrite(LD2, LOW);
digitalWrite(LD3, LOW);
Serial.begin(115200);
mp3.begin(9600);
mp3.reset();
mp3.setVolume(90);
mp3.setLoopMode(MP3_LOOP_NONE);
Serial.println("HELMET CONTROLLER ON");
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("IIT (ISM)");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,18);
display.print(" DHANBAD");
display.display();
delay(100); // Pause for 2 seconds
while (myAHT10.begin() != true)
{
Serial.println(F("AHT10 not connected ")); //(F()) save string to flash & keeps dynamic memory free
delay(1000);
}
Serial.println(F("AHT10 OK"));
if(mp3.getStatus() != MP3_STATUS_PLAYING)
{
mp3.playFileByIndexNumber(14);
}
}
void loop() {
// put your main code here, to run repeatedly:
y++;
b++;
bat = analogRead(A0);
batf = (bat * 5.0)/1023;
batf = batf * 10.9;
float t = myAHT10.readTemperature();
float h = myAHT10.readHumidity();
tempe=t;
humi=h;
for(a=0;a<100;a++){
gas = analogRead(A1);
gas = (gas * 5.0)/1023;
if(gas<=0.4)
{
gas=0;
}
gas = ((gas * 5) - 2);
gas = gas / 1.6;
avg = avg + gas;
}
gas = avg / 100;
avg = 0;
co = analogRead(A3);
co = (co * 10)/1.023;
if(co <= 0){co=0;}
nh3 = analogRead(A6);
nh3 =(int) (nh3 * 50)/102.3;
no2 = analogRead(A7);
no2f = (no2 * 5.0)/1023;
no2f = (no2f * 1.99)+0.05;
if(t>40 || h>70 || gas>2 )
{
if(t>40)
{
mp3.playFileByIndexNumber(22);
mp3.playFileByIndexNumber(16);
mp3.playFileByIndexNumber(15);
}
if(h>60)
{
mp3.playFileByIndexNumber(18);
mp3.playFileByIndexNumber(16);
mp3.playFileByIndexNumber(15);
}
if(gas>2)
{
mp3.playFileByIndexNumber(28);
mp3.playFileByIndexNumber(16);
mp3.playFileByIndexNumber(15);
}
}
else
{
switch (b){
case 1:
gen = tempe * 100;
temp();
break;
case 2:
gen = humi * 100;
hum();
break;
case 3:
gen = gas * 100;
meth();
break;
case 4:
gen = co * 10;
carbon();
break;
case 5:
gen =int( nh3 * 10);
amonia(gen);
break;
case 6:
gen = no2f * 100;
nitro();
break;
default:
b=0;
break;
}
}
delay(75);
}
void temp(){
Serial.print("genh:");
Serial.print(gen);
d1 = gen / 1000;
d2 = d1 * 1000;
gen = gen - d2;
d2 = gen / 100;
d2 = d2 + 1;
d1 = d1 + 1;
Serial.print(" dt1:");
Serial.print(d1);
Serial.print(" dt2:");
Serial.println(d2);
mp3.playFileByIndexNumber(22);//
delay(200);
mp3.playFileByIndexNumber(d1);//
delay(100);
mp3.playFileByIndexNumber(d2);
delay(100);
mp3.playFileByIndexNumber(23);//
delay(1000);
}
void hum(){
Serial.print("genh:");
Serial.print(gen);
d1 = gen / 1000;
d2 = d1 * 1000;
gen = gen - d2;
d2 = gen / 100;
d2 = d2 + 1;
d1 = d1 + 1;
Serial.print(" dh1:");
Serial.print(d1);
Serial.print(" dh2:");
Serial.println(d2);
mp3.playFileByIndexNumber(18);//
delay(300);
mp3.playFileByIndexNumber(d1);//
delay(300);
mp3.playFileByIndexNumber(d2);
delay(300);
mp3.playFileByIndexNumber(19);//
delay(1000);
gen = 0;
}
void meth(){
Serial.print("gen m:");
Serial.print(gen);
d1 = gen / 100;
d2 = d1 * 100;
gen = gen - d2;
d2 = gen / 10;
d3 = gen - (d2*10);
d2 = d2 + 1;
d1 = d1 + 1;
d3 = d3 + 1;
Serial.print(" dm1:");
Serial.print(d1);
Serial.print(" dm2:");
Serial.print(d2);
Serial.print(" dm3:");
Serial.println(d3);
mp3.playFileByIndexNumber(28);//
delay(300);
mp3.playFileByIndexNumber(d1);//
delay(300);
mp3.playFileByIndexNumber(24);//
delay(300);
mp3.playFileByIndexNumber(d2);
delay(300);
mp3.playFileByIndexNumber(d3);
delay(300);
mp3.playFileByIndexNumber(29);//
delay(1500);
gen = 0;
}
void nitro(){
Serial.print("gen no2:");
Serial.print(gen);
d1 = gen / 100;
d2 = d1 * 100;
gen = gen - d2;
d2 = gen / 10;
d3 = gen - (d2*10);
d2 = d2 + 1;
d1 = d1 + 1;
d3 = d3 + 1;
Serial.print(" dno1:");
Serial.print(d1);
Serial.print(" dno2:");
Serial.print(d2);
Serial.print(" dno3:");
Serial.println(d3);
mp3.playFileByIndexNumber(27);//
delay(300);
mp3.playFileByIndexNumber(d1);//
delay(300);
mp3.playFileByIndexNumber(24);//
delay(300);
mp3.playFileByIndexNumber(d2);
delay(300);
mp3.playFileByIndexNumber(d3);
delay(300);
mp3.playFileByIndexNumber(21);//
delay(500);
gen = 0;
}
void carbon(){
Serial.print("gen co:");
Serial.print(gen);
d1 = gen / 1000;
d2 = d1 * 1000;
gen = gen - d2;
d2 = gen / 100;
d3 = d2 * 100;
gen = gen - d3;
d3 = gen / 10;
d2 = d2 + 1;
d1 = d1 + 1;
d3 = d3 + 1;
Serial.print(" dco1:");
Serial.print(d1);
Serial.print(" dco2:");
Serial.print(d2);
Serial.print(" dco3:");
Serial.println(d3);
mp3.playFileByIndexNumber(25);//
delay(300);
mp3.playFileByIndexNumber(d1);//
delay(300);
mp3.playFileByIndexNumber(d2);
delay(300);
mp3.playFileByIndexNumber(d3);
delay(300);
mp3.playFileByIndexNumber(21);//
delay(1000);
gen = 0;
}
void amonia(){
Serial.print("gen ammo:");
Serial.print(gen);
d1 =int( gen / 1000);
d2 = d1 * 1000;
gen =int( gen - d2);
d2 =int( gen / 100);
d3 = d2 * 100;
gen =int( gen - d3);
d3 =int( gen / 10);
d2 = d2 + 1;
d1 = d1 + 1;
d3 = d3 + 1;
mp3.playFileByIndexNumber(26);//
delay(300);
mp3.playFileByIndexNumber(d1);//
delay(300);
mp3.playFileByIndexNumber(21);//
delay(300);
mp3.playFileByIndexNumber(d2);
delay(300);
mp3.playFileByIndexNumber(d3);
delay(1000);
Serial.print(" damo1:");
Serial.print(d1);
Serial.print(" damo2:");
Serial.print(d2);
Serial.print(" damo3:");
Serial.println(d3);
gen = 0;
}