i have no idea
i want use dht sensor and ambilight at same time in 1 arduino nano
I am trying run this not working, if i write dht code first then ambilight doesn't work and same if i write ambilght first then dht doesn't work too
this is for example
#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
LiquidCrystal_I2C lcd(0x27, 16, 4);
#define DHTPIN 2
#define DHTTYPE DHT11
#define pwm 3
#define LED_PIN 13
#define NUM_LEDS 8
#define serialRate 115200
DHT dht(DHTPIN, DHTTYPE);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, LED_PIN, NEO_GRB + NEO_KHZ800);
#include "FastLED.h"
#define NUM_LED 96
#define DATA_PIN 6
#define serialRate 115200
uint8_t prefix[] = { 'A', 'd', 'a' }, hi, lo, chk, i;
CRGB leds[NUM_LED];
void setup()
{
strip.begin();
strip.show();
analogWrite(pwm, 255);
Serial.begin(9600);
dht.begin();
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LED);
LEDS.showColor(CRGB(255, 0, 0));
delay(500);
LEDS.showColor(CRGB(0, 255, 0));
delay(500);
LEDS.showColor(CRGB(0, 0, 255));
delay(500);
LEDS.showColor(CRGB(0, 0, 0));
Serial.begin(serialRate);
Serial.print("Ada\n");
strip.begin();
strip.show();
lcd.begin(16, 2);
lcd.backlight();
delay(1000);
}
void loop() {
//DHT11
float t = dht.readTemperature();
float h = dht.readHumidity();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
lcd.setCursor(8, 0);
lcd.print("Croot ");
lcd.setCursor(10, 1);
lcd.print("Croot ");
return;
}
lcd.setCursor(0, 1);
lcd.write(1);
lcd.print(t);
lcd.print("C");
delay(500);
lcd.setCursor(8, 1);
lcd.print(h, 0);
lcd.print("%");
delay(500);
lcd.setCursor(12, 1);
if (t < 35.5)
{
analogWrite(pwm, 0);
lcd.print("0% ");
//fadeAmount = -fadeAmount;
strip.setBrightness(50);
for (int i = 0; i < 20; i++) { //biru
colorWipe(strip.Color(14, 35, 180), 50);
colorWipe(strip.Color(16, 37, 185), 50);
colorWipe(strip.Color(18, 39, 190), 50);
colorWipe(strip.Color(20, 41, 195), 50);
colorWipe(strip.Color(18, 39, 190), 50);
colorWipe(strip.Color(16, 37, 185), 50);
strip.show();
}
delay(1000);
} else if (t == 36) {
analogWrite(pwm, 25);
lcd.print("10% ");
strip.setBrightness(50);
for (int i = 0; i < 20; i++) { //oren
colorWipe(strip.Color(255, 241, 235), 50);
colorWipe(strip.Color(255, 238, 207), 50);
colorWipe(strip.Color(253, 228, 169), 50);
colorWipe(strip.Color(20, 41, 195), 50);
colorWipe(strip.Color(255, 197, 125), 50);
colorWipe(strip.Color(255, 183, 93), 50);
colorWipe(strip.Color(255, 197, 125), 50);
colorWipe(strip.Color(20, 41, 195), 50);
colorWipe(strip.Color(253, 228, 169), 50);
colorWipe(strip.Color(255, 238, 207), 50);
strip.show();
}
delay(1000);
} else if (t == 36.5) {
analogWrite(pwm, 51);
lcd.print("20% ");
strip.setBrightness(50);
for (int i = 0; i < 20; i++) { //merah
colorWipe(strip.Color(255, 236, 236), 50);
colorWipe(strip.Color(255, 214, 214), 50);
colorWipe(strip.Color(255, 186, 186), 50);
colorWipe(strip.Color(255, 162, 162), 50);
colorWipe(strip.Color(255, 152, 152), 50);
colorWipe(strip.Color(255, 138, 138), 50);
colorWipe(strip.Color(255, 152, 152), 50);
colorWipe(strip.Color(255, 162, 162), 50);
colorWipe(strip.Color(255, 186, 186), 50);
colorWipe(strip.Color(255, 214, 214), 50);
strip.show();
}
delay(1000);
}
delay(3000);
//dht code
//AMBATULIGHT
for (i = 0; i < sizeof prefix; ++i) {
waitLoop:
while (!Serial.available())
;
;
if (prefix[i] == Serial.read()) continue;
// otherwise, start over
i = 0;
goto waitLoop;
}
while (!Serial.available())
;
;
hi = Serial.read();
while (!Serial.available())
;
;
lo = Serial.read();
while (!Serial.available())
;
;
chk = Serial.read();
if (chk != (hi ^ lo ^ 0x55)) {
i = 0;
goto waitLoop;
}
memset(leds, 0, NUM_LED * sizeof(struct CRGB));
// Read the transmission data and set LED values
for (uint8_t i = 0; i < NUM_LED; i++) {
byte r, g, b;
while (!Serial.available())
;
r = Serial.read();
while (!Serial.available())
;
g = Serial.read();
while (!Serial.available())
;
b = Serial.read();
leds[i].r = r;
leds[i].g = g;
leds[i].b = b;
}
FastLED.show();
}
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
//ambilight code
}