My servo needs to be controlled with MIT app inventor, so I wrote some code but it doesn't work. I also have a spectrometer and soil moisture sensor, so is the code from that messing it up? I ran the servo code separately and it worked with my app, only when I combined the code did it stop working. I'm kind of new to Arduino, so my code isn't great. Any tips would be greatly appreciated!! (This is on a Nano by the way.)
#include <Servo.h>
#include <Adafruit_AS7341.h>
Adafruit_AS7341 as7341;
Servo ser;
int poser = 90;
int servo;
char Incoming_Value = 0;
int moisturePin = A0;
int moistureValue = 0;
void setup() {
Serial.begin(9600);
as7341.enableLED(true);
ser.attach(D7);
while (!Serial) {
delay(1);
}
if (!as7341.begin()) {
Serial.println("Could not find AS7341");
while (1) {
delay(10);
}
}
as7341.setATIME(100);
as7341.setASTEP(999);
as7341.setGain(AS7341_GAIN_256X);
}
void loop() {
moistureValue = analogRead(moisturePin);
as7341.enableLED(true);
while (Serial.available())
{
servo = Serial.read();
poser = servo;
ser.write(poser);
delay(15);
}
if (!as7341.readAllChannels()) {
Serial.println("Error reading all channels!");
return;
}
Serial.println(moistureValue);
Serial.println("|");
specValue();
Serial.println("|");
Serial.println();
delay(1000);
}
void specValue() {
Serial.print("blue 445nm: ");
Serial.print(as7341.getChannel(AS7341_CHANNEL_445nm_F2));
Serial.print("red 630nm: ");
Serial.print(as7341.getChannel(AS7341_CHANNEL_630nm_F7));
Serial.print("yellow 590nm: ");
Serial.print(as7341.getChannel(AS7341_CHANNEL_590nm_F6));
}