Hello everybody !
I am using an arduino to handle too much thing for a NodeMCU.
But still, I need wifi =p
I am trying to use a Segmented switch, with 5 cases and want each on of this case doing something different to my arduino.
I could use a digitalWrite for each case of my NodeMCU, but the thing is, I already use D1 D2, so the only left pins are D5 D6 D7 (dont need boot issues if other pins re pulled low/high).
So I am good to an analogWrite(pin,1);analogWrite(pin,2); and so, for my differents cases.
BLYNK_WRITE(V1) {
switch (param.asInt())
{
case 1: { // Item 1
nbjoueurs = 2 ;
break;
}
case 2: { // Item 2
Serial.println("3");
nbjoueurs = 3 ;
break;
}
case 3: { // Item 3
Serial.println("4");
nbjoueurs = 4 ;
break;
}
case 4: { // Item 4
Serial.println("5");
nbjoueurs = 5 ;
break;
}
case 5: { // Item 5
Serial.println("6");
nbjoueurs = 6 ;
break;
}
}
}
Then in my loop :
if (nbjoueurs == 2)
{
analogWrite(pinnb, 2);
Serial.println("2");
}
else if (nbjoueurs == 3)
{
analogWrite(pinnb, 3);
Serial.println("3");
}
else if (nbjoueurs == 4)
{
analogWrite(pinnb, 4);
Serial.println("4");
}
else if (nbjoueurs == 5)
{
analogWrite(pinnb, 5);
Serial.println("5");
}
else if (nbjoueurs == 6)
{
analogWrite(pinnb, 6);
Serial.println("6");
}
With pinnb set to #define pinnb 12 //
With my arduino, I am reading this pin with A0
int nbesp = A0;
and in my loop :
nb = analogRead(nbesp); // read the input pin
Serial.println(nb);
But when serialprinting to check if its ok when I push the segmented switch, all I got with the Mega is radnom value from 664 to 667, not 2, 3, 4, 5, 6 …
What I am doing wrong ? =p
Thanks a lot !