<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Arduino%3A_Read_ASCII_String</id>
	<title>Arduino: Read ASCII String - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Arduino%3A_Read_ASCII_String"/>
	<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_Read_ASCII_String&amp;action=history"/>
	<updated>2026-04-20T17:11:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_Read_ASCII_String&amp;diff=45288&amp;oldid=prev</id>
		<title>Onnowpurbo: New page: This sketch uses the Serial.parseInt() function to locate values separated by a non-alphanumeric character. Often people use a comma to indicate different pieces of information (this forma...</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_Read_ASCII_String&amp;diff=45288&amp;oldid=prev"/>
		<updated>2015-12-09T11:48:12Z</updated>

		<summary type="html">&lt;p&gt;New page: This sketch uses the Serial.parseInt() function to locate values separated by a non-alphanumeric character. Often people use a comma to indicate different pieces of information (this forma...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This sketch uses the Serial.parseInt() function to locate values separated by a non-alphanumeric character. Often people use a comma to indicate different pieces of information (this format is commonly referred to as comma-separated-values or CSV), but other characters like a space or a period will work too. The values are parsed into integers and used to determine the color of a RGB LED. You&amp;#039;ll use the Arduino Software (IDE) serial monitor to send strings like &amp;quot;5,220,70&amp;quot; to the board to change the light color. &lt;br /&gt;
&lt;br /&gt;
==Hardware==&lt;br /&gt;
&lt;br /&gt;
* Arduino or Genuino Board&lt;br /&gt;
* common anode RGB LED&lt;br /&gt;
* 3 220 ohm resistors&lt;br /&gt;
* hook-up wires&lt;br /&gt;
* breadboard &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Rangkaian==&lt;br /&gt;
&lt;br /&gt;
[[Image:ReadASCIIStringFritz.png|center|200px|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[Image:ReadASCIIStringSche.png|center|200px|thumb]]&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
   Reading a serial ASCII-encoded string.&lt;br /&gt;
 &lt;br /&gt;
  This sketch demonstrates the Serial parseInt() function.&lt;br /&gt;
  It looks for an ASCII string of comma-separated values.&lt;br /&gt;
  It parses them into ints, and uses those to fade an RGB LED. &lt;br /&gt;
 &lt;br /&gt;
  Circuit: Common-anode RGB LED wired like so:&lt;br /&gt;
  * Red cathode: digital pin 3&lt;br /&gt;
  * Green cathode: digital pin 5&lt;br /&gt;
  * blue cathode: digital pin 6&lt;br /&gt;
  * anode: +5V&lt;br /&gt;
 &lt;br /&gt;
  created 13 Apr 2012&lt;br /&gt;
  by Tom Igoe&lt;br /&gt;
 &lt;br /&gt;
  This example code is in the public domain.&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 // pins for the LEDs:&lt;br /&gt;
 const int redPin = 3;&lt;br /&gt;
 const int greenPin = 5;&lt;br /&gt;
 const int bluePin = 6;&lt;br /&gt;
 &lt;br /&gt;
 void setup() {&lt;br /&gt;
   // initialize serial:&lt;br /&gt;
   Serial.begin(9600);&lt;br /&gt;
   // make the pins outputs:&lt;br /&gt;
   pinMode(redPin, OUTPUT);&lt;br /&gt;
   pinMode(greenPin, OUTPUT);&lt;br /&gt;
   pinMode(bluePin, OUTPUT);&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 void loop() {&lt;br /&gt;
   // if there&amp;#039;s any serial available, read it:&lt;br /&gt;
   while (Serial.available() &amp;gt; 0) {&lt;br /&gt;
 &lt;br /&gt;
     // look for the next valid integer in the incoming serial stream:&lt;br /&gt;
     int red = Serial.parseInt();&lt;br /&gt;
     // do it again:&lt;br /&gt;
     int green = Serial.parseInt();&lt;br /&gt;
     // do it again:&lt;br /&gt;
     int blue = Serial.parseInt();&lt;br /&gt;
 &lt;br /&gt;
     // look for the newline. That&amp;#039;s the end of your&lt;br /&gt;
     // sentence:&lt;br /&gt;
     if (Serial.read() == &amp;#039;\n&amp;#039;) {&lt;br /&gt;
       // constrain the values to 0 - 255 and invert&lt;br /&gt;
       // if you&amp;#039;re using a common-cathode LED, just use &amp;quot;constrain(color, 0, 255);&amp;quot;&lt;br /&gt;
       red = 255 - constrain(red, 0, 255);&lt;br /&gt;
       green = 255 - constrain(green, 0, 255);&lt;br /&gt;
       blue = 255 - constrain(blue, 0, 255); &lt;br /&gt;
 &lt;br /&gt;
       // fade the red, green, and blue legs of the LED:&lt;br /&gt;
       analogWrite(redPin, red);&lt;br /&gt;
       analogWrite(greenPin, green);&lt;br /&gt;
       analogWrite(bluePin, blue); &lt;br /&gt;
 &lt;br /&gt;
       // print the three numbers in one string as hexadecimal:&lt;br /&gt;
       Serial.print(red, HEX);&lt;br /&gt;
       Serial.print(green, HEX);&lt;br /&gt;
       Serial.println(blue, HEX);&lt;br /&gt;
     }&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
</feed>