アナログ出力のスケッチ(プログラム)
//analogWrite
int led = 9; // the PWM pin the LED is attached to
int brightness; // how bright the LED is
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
inputString.reserve(100);
}
void loop()
{
//analogWrite(led, brightness);
if (stringComplete)
{
brightness =inputString.toInt() ;
analogWrite(led, brightness);
Serial.print(inputString);
inputString = "";
stringComplete = false;
delay(100);
}
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n')
{
stringComplete = true;
}
}
}
Arduinoスケッチ_テキストファイルは以下から参照できます。
Arduinoスケッチ_テキストファイルにいく