wiring diagram
รูปที่ 1
โค้ดที่18.1 (Code Arduino)
int led = 10;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop()
{
int x,y;
x = analogRead(A0);
y = map(x,0,1023,0,255);
Serial.print("x = ");Serial.println(x);
Serial.print("y = ");Serial.println(y);
analogWrite(led,y);
}
โค้ดที่18.2 (Code Arduino)
int red = 11;int green = 10;int blue = 9;void setup(){ Serial.begin(9600); pinMode(red,OUTPUT); pinMode(green,OUTPUT); pinMode(blue,OUTPUT); }void loop(){ int x,y,z,r,s,t; x = analogRead(A0); y = analogRead(A1); z = analogRead(A2); r = map(x,0,1023,0,255); s = map(y,0,1023,0,255); t = map(z,0,1023,0,255); Serial.print("r = ");Serial.println(r); Serial.print("s = ");Serial.println(s); Serial.print("t = ");Serial.println(t); analogWrite(red,r); analogWrite(green,s); analogWrite(blue,t);
}
โค้ดที่18.3 (Code Arduino)
int red = 11;
int green = 10;
int blue = 9;
void setup()
{
Serial.begin(9600);
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
}
void loop()
{
int x,y,z,r,s,t;
x = analogRead(A0);
y = analogRead(A1);
z = analogRead(A2);
r = map(x,0,1023,0,255);
s = map(y,0,1023,0,255);
t = map(z,0,1023,0,255);
Serial.print("r = ");Serial.println(r);
Serial.print("s = ");Serial.println(s);
Serial.print("t = ");Serial.println(t);
analogWrite(red,r);
analogWrite(green,s);
analogWrite(blue,t);
}
โค้ดที่18.1 (Code Arduino)
int led = 10;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop()
{
int x,y;
x = analogRead(A0);
y = map(x,0,1023,0,255);
Serial.print("x = ");Serial.println(x);
Serial.print("y = ");Serial.println(y);
analogWrite(led,y);
}
โค้ดที่18.2 (Code Arduino)
int red = 11;int green = 10;int blue = 9;void setup(){ Serial.begin(9600); pinMode(red,OUTPUT); pinMode(green,OUTPUT); pinMode(blue,OUTPUT); }void loop(){ int x,y,z,r,s,t; x = analogRead(A0); y = analogRead(A1); z = analogRead(A2); r = map(x,0,1023,0,255); s = map(y,0,1023,0,255); t = map(z,0,1023,0,255); Serial.print("r = ");Serial.println(r); Serial.print("s = ");Serial.println(s); Serial.print("t = ");Serial.println(t); analogWrite(red,r); analogWrite(green,s); analogWrite(blue,t);
}
โค้ดที่18.3 (Code Arduino)
int red = 11;
int green = 10;
int blue = 9;
void setup()
{
Serial.begin(9600);
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
}
void loop()
{
int x,y,z,r,s,t;
x = analogRead(A0);
y = analogRead(A1);
z = analogRead(A2);
r = map(x,0,1023,0,255);
s = map(y,0,1023,0,255);
t = map(z,0,1023,0,255);
Serial.print("r = ");Serial.println(r);
Serial.print("s = ");Serial.println(s);
Serial.print("t = ");Serial.println(t);
analogWrite(red,r);
analogWrite(green,s);
analogWrite(blue,t);
}