فهرست منبع

Pretty printed the Arduino code with astyle

Baozhu Zuo 6 سال پیش
والد
کامیت
4687bbbc3c

+ 193 - 224
GroveColorSensor.cpp

@@ -4,257 +4,226 @@
 
 // Default constructor
 GroveColorSensor::GroveColorSensor()
-	: triggerMode_(INTEG_MODE_FREE | INTEG_PARAM_PULSE_COUNT1)
-	, interruptSource_(INT_SOURCE_CLEAR)
-	, interruptMode_(INTR_LEVEL | INTR_PERSIST_EVERY)
-	, gainAndPrescaler_(GAIN_1 | PRESCALER_1)
-	, sensorAddress_(COLOR_SENSOR_ADDR)
-{	
-	GroveColorSensor::setTimingReg(); 
-	GroveColorSensor::setInterruptSourceReg();  
-	GroveColorSensor::setInterruptControlReg(); 
-	GroveColorSensor::setGain(); 
-	GroveColorSensor::setEnableADC(); 
+    : triggerMode_(INTEG_MODE_FREE | INTEG_PARAM_PULSE_COUNT1)
+    , interruptSource_(INT_SOURCE_CLEAR)
+    , interruptMode_(INTR_LEVEL | INTR_PERSIST_EVERY)
+    , gainAndPrescaler_(GAIN_1 | PRESCALER_1)
+    , sensorAddress_(COLOR_SENSOR_ADDR) {
+    GroveColorSensor::setTimingReg();
+    GroveColorSensor::setInterruptSourceReg();
+    GroveColorSensor::setInterruptControlReg();
+    GroveColorSensor::setGain();
+    GroveColorSensor::setEnableADC();
 }
 
 // Constructor with parameters
 GroveColorSensor::GroveColorSensor(
-	  const int& triggerMode
-	, const int& interruptSource
-	, const int& interruptMode
-	, const int& gainAndPrescaler
-	, const int& sensorAddress)
-	: triggerMode_(triggerMode)
-	, interruptSource_(interruptSource)
-	, interruptMode_(interruptMode)
-	, gainAndPrescaler_(gainAndPrescaler)
-	, sensorAddress_(sensorAddress) 
+    const int& triggerMode
+    , const int& interruptSource
+    , const int& interruptMode
+    , const int& gainAndPrescaler
+    , const int& sensorAddress)
+    : triggerMode_(triggerMode)
+    , interruptSource_(interruptSource)
+    , interruptMode_(interruptMode)
+    , gainAndPrescaler_(gainAndPrescaler)
+    , sensorAddress_(sensorAddress)
 {}
 
-void GroveColorSensor::setTimingReg()
-{
-	Wire.beginTransmission(sensorAddress_);
-	Wire.write(REG_TIMING);
-	Wire.write(triggerMode_);
-	Wire.endTransmission();  
-	delay(10); 
+void GroveColorSensor::setTimingReg() {
+    Wire.beginTransmission(sensorAddress_);
+    Wire.write(REG_TIMING);
+    Wire.write(triggerMode_);
+    Wire.endTransmission();
+    delay(10);
 }
 
-void GroveColorSensor::setInterruptSourceReg()
-{
-	Wire.beginTransmission(sensorAddress_);
-	Wire.write(REG_INT_SOURCE);
-	Wire.write(interruptSource_);
-	Wire.endTransmission();  
-	delay(10);
+void GroveColorSensor::setInterruptSourceReg() {
+    Wire.beginTransmission(sensorAddress_);
+    Wire.write(REG_INT_SOURCE);
+    Wire.write(interruptSource_);
+    Wire.endTransmission();
+    delay(10);
 }
 
-void GroveColorSensor::setInterruptControlReg()
-{
-	Wire.beginTransmission(sensorAddress_);
-	Wire.write(REG_INT);
-	Wire.write(interruptMode_);
-	Wire.endTransmission();  
-	delay(10);
+void GroveColorSensor::setInterruptControlReg() {
+    Wire.beginTransmission(sensorAddress_);
+    Wire.write(REG_INT);
+    Wire.write(interruptMode_);
+    Wire.endTransmission();
+    delay(10);
 }
 
-void GroveColorSensor::setGain()
-{
-	Wire.beginTransmission(sensorAddress_);
-	Wire.write(REG_GAIN);
-	Wire.write(gainAndPrescaler_);
-	Wire.endTransmission();
+void GroveColorSensor::setGain() {
+    Wire.beginTransmission(sensorAddress_);
+    Wire.write(REG_GAIN);
+    Wire.write(gainAndPrescaler_);
+    Wire.endTransmission();
 }
 
-void GroveColorSensor::setEnableADC()
-{
-	Wire.beginTransmission(sensorAddress_);
-	Wire.write(REG_CTL);
-	Wire.write(CTL_DAT_INIITIATE);
-	Wire.endTransmission();  
-	delay(10);  
+void GroveColorSensor::setEnableADC() {
+    Wire.beginTransmission(sensorAddress_);
+    Wire.write(REG_CTL);
+    Wire.write(CTL_DAT_INIITIATE);
+    Wire.endTransmission();
+    delay(10);
 }
 
-void GroveColorSensor::clearInterrupt()
-{
-	Wire.beginTransmission(sensorAddress_);
-	Wire.write(CLR_INT);
-	Wire.endTransmission(); 
+void GroveColorSensor::clearInterrupt() {
+    Wire.beginTransmission(sensorAddress_);
+    Wire.write(CLR_INT);
+    Wire.endTransmission();
 }
 
-void GroveColorSensor::readRGB()
-{
-	Wire.beginTransmission(sensorAddress_);
-	Wire.write(REG_BLOCK_READ);
-	Wire.endTransmission();
-	
-	Wire.requestFrom(sensorAddress_, 8);
-	
-	// if two bytes were received
-	if(8 <= Wire.available())
-	{
-		int i;
-		for(i = 0; i < 8; ++i)
-		{
-			readingdata_[i] = Wire.read();
-			//Serial.println(readingdata_[i], BIN);
-		}
-	}
-	green_	= readingdata_[1] * 256 + readingdata_[0];
-	red_ 	= readingdata_[3] * 256 + readingdata_[2];
-	blue_	= readingdata_[5] * 256 + readingdata_[4];
-	clear_	= readingdata_[7] * 256 + readingdata_[6];
-	
-	Serial.print("The RGB value are: RGB( ");
-	Serial.print(red_,DEC);
-	Serial.print(", ");
-	Serial.print(green_,DEC);
-	Serial.print(", ");
-	Serial.print(blue_,DEC);
-	Serial.println(" )");
-	Serial.print("The Clear channel value is: ");
-	Serial.println(clear_,DEC);
+void GroveColorSensor::readRGB() {
+    Wire.beginTransmission(sensorAddress_);
+    Wire.write(REG_BLOCK_READ);
+    Wire.endTransmission();
+
+    Wire.requestFrom(sensorAddress_, 8);
+
+    // if two bytes were received
+    if (8 <= Wire.available()) {
+        int i;
+        for (i = 0; i < 8; ++i) {
+            readingdata_[i] = Wire.read();
+            //Serial.println(readingdata_[i], BIN);
+        }
+    }
+    green_	= readingdata_[1] * 256 + readingdata_[0];
+    red_ 	= readingdata_[3] * 256 + readingdata_[2];
+    blue_	= readingdata_[5] * 256 + readingdata_[4];
+    clear_	= readingdata_[7] * 256 + readingdata_[6];
+
+    Serial.print("The RGB value are: RGB( ");
+    Serial.print(red_, DEC);
+    Serial.print(", ");
+    Serial.print(green_, DEC);
+    Serial.print(", ");
+    Serial.print(blue_, DEC);
+    Serial.println(" )");
+    Serial.print("The Clear channel value is: ");
+    Serial.println(clear_, DEC);
 }
 
-void GroveColorSensor::readRGB(int *red, int *green, int *blue)
-{
-	Wire.beginTransmission(sensorAddress_);
-	Wire.write(REG_BLOCK_READ);
-	Wire.endTransmission();
-	
-	Wire.requestFrom(sensorAddress_, 8);
-
-	// if two bytes were received
-	if(8 <= Wire.available())
-	{
-		int i;
-		for(i = 0; i < 8; ++i)
-		{
-			readingdata_[i] = Wire.read();
-			//Serial.println(readingdata_[i], BIN);
-		}
-	}
-	green_	= readingdata_[1] * 256 + readingdata_[0];
-	red_ 	= readingdata_[3] * 256 + readingdata_[2];
-	blue_	= readingdata_[5] * 256 + readingdata_[4];
-	clear_	= readingdata_[7] * 256 + readingdata_[6];
-	
-	double tmp;
-	int maxColor;
-	
-	if ( ledStatus == 1 )
-	{
-		red_  = red_  * 1.70;
-		blue_ = blue_ * 1.35;
-
-		maxColor = max(red_, green_);
-		maxColor = max(maxColor, blue_);
-	   
-		if(maxColor > 255)
-		{
-			tmp = 250.0/maxColor;
-			green_	*= tmp;
-			red_ 	*= tmp;
-			blue_	*= tmp;
-		}
-	}
-	if ( ledStatus == 0 )
-	{
-		maxColor = max(red_, green_);
-		maxColor = max(maxColor, blue_);
-	   
-		tmp = 250.0/maxColor;
-		green_	*= tmp;
-		red_ 	*= tmp;
-		blue_	*= tmp;
-
-	}
-	
-	int minColor = min(red_, green_);
-	minColor = min(minColor, blue_);
-	maxColor = max(red_, green_);
-	maxColor = max(maxColor, blue_);
-	
-	int greenTmp = green_;
-	int redTmp 	 = red_;
-	int blueTmp	 = blue_;
-	
-//when turn on LED, need to adjust the RGB data,otherwise it is almost the white color
-	if(red_ < 0.8*maxColor && red_ >= 0.6*maxColor)
-	{
-		red_ *= 0.4;
+void GroveColorSensor::readRGB(int* red, int* green, int* blue) {
+    Wire.beginTransmission(sensorAddress_);
+    Wire.write(REG_BLOCK_READ);
+    Wire.endTransmission();
+
+    Wire.requestFrom(sensorAddress_, 8);
+
+    // if two bytes were received
+    if (8 <= Wire.available()) {
+        int i;
+        for (i = 0; i < 8; ++i) {
+            readingdata_[i] = Wire.read();
+            //Serial.println(readingdata_[i], BIN);
+        }
     }
-	else if(red_ < 0.6*maxColor)
-	{
-		red_ *= 0.2;
+    green_	= readingdata_[1] * 256 + readingdata_[0];
+    red_ 	= readingdata_[3] * 256 + readingdata_[2];
+    blue_	= readingdata_[5] * 256 + readingdata_[4];
+    clear_	= readingdata_[7] * 256 + readingdata_[6];
+
+    double tmp;
+    int maxColor;
+
+    if (ledStatus == 1) {
+        red_  = red_  * 1.70;
+        blue_ = blue_ * 1.35;
+
+        maxColor = max(red_, green_);
+        maxColor = max(maxColor, blue_);
+
+        if (maxColor > 255) {
+            tmp = 250.0 / maxColor;
+            green_	*= tmp;
+            red_ 	*= tmp;
+            blue_	*= tmp;
+        }
     }
-	
-	if(green_ < 0.8*maxColor && green_ >= 0.6*maxColor)
-	{
-		green_ *= 0.4;
+    if (ledStatus == 0) {
+        maxColor = max(red_, green_);
+        maxColor = max(maxColor, blue_);
+
+        tmp = 250.0 / maxColor;
+        green_	*= tmp;
+        red_ 	*= tmp;
+        blue_	*= tmp;
+
     }
-	else if(green_ < 0.6*maxColor)
-	{
-		if (maxColor == redTmp && greenTmp >= 2*blueTmp && greenTmp >= 0.2*redTmp)				//orange
-		{
-			green_ *= 5;
-		}
-		green_ *= 0.2;
+
+    int minColor = min(red_, green_);
+    minColor = min(minColor, blue_);
+    maxColor = max(red_, green_);
+    maxColor = max(maxColor, blue_);
+
+    int greenTmp = green_;
+    int redTmp 	 = red_;
+    int blueTmp	 = blue_;
+
+    //when turn on LED, need to adjust the RGB data,otherwise it is almost the white color
+    if (red_ < 0.8 * maxColor && red_ >= 0.6 * maxColor) {
+        red_ *= 0.4;
+    } else if (red_ < 0.6 * maxColor) {
+        red_ *= 0.2;
     }
-	
-	if(blue_ < 0.8*maxColor && blue_ >= 0.6*maxColor)
-	{
-		blue_ *= 0.4;
+
+    if (green_ < 0.8 * maxColor && green_ >= 0.6 * maxColor) {
+        green_ *= 0.4;
+    } else if (green_ < 0.6 * maxColor) {
+        if (maxColor == redTmp && greenTmp >= 2 * blueTmp && greenTmp >= 0.2 * redTmp) {			//orange
+            green_ *= 5;
+        }
+        green_ *= 0.2;
     }
-	else if(blue_ < 0.6*maxColor)
-	{
-		if (maxColor == redTmp && greenTmp >= 2*blueTmp && greenTmp >= 0.2*redTmp)				//orange
-		{
-			blue_ *= 0.5;
-		}
-		if (maxColor == redTmp && greenTmp <= blueTmp && blueTmp >= 0.2*redTmp)					//pink
-		{
-			blue_  *= 5;
-		}
-		blue_ *= 0.2;
+
+    if (blue_ < 0.8 * maxColor && blue_ >= 0.6 * maxColor) {
+        blue_ *= 0.4;
+    } else if (blue_ < 0.6 * maxColor) {
+        if (maxColor == redTmp && greenTmp >= 2 * blueTmp && greenTmp >= 0.2 * redTmp) {			//orange
+            blue_ *= 0.5;
+        }
+        if (maxColor == redTmp && greenTmp <= blueTmp && blueTmp >= 0.2 * redTmp) {				//pink
+            blue_  *= 5;
+        }
+        blue_ *= 0.2;
     }
-	
-	minColor = min(red_, green_);
-	minColor = min(minColor, blue_);
-	if(maxColor == green_ && red_ >= 0.85*maxColor && minColor == blue_)						//yellow
-	{
-		red_ = maxColor;
-		blue_ *= 0.4;
+
+    minColor = min(red_, green_);
+    minColor = min(minColor, blue_);
+    if (maxColor == green_ && red_ >= 0.85 * maxColor && minColor == blue_) {					//yellow
+        red_ = maxColor;
+        blue_ *= 0.4;
     }
-	
-	*red   = red_;
-	*green = green_;
-	*blue  = blue_;
+
+    *red   = red_;
+    *green = green_;
+    *blue  = blue_;
 }
 
-void GroveColorSensor::calculateCoordinate()
-{
-	double X;
-	double Y;
-	double Z;
-	double x;
-	double y;
-	
-	X = (-0.14282) * red_ + (1.54924) * green_ + (-0.95641) * blue_;
-	Y = (-0.32466) * red_ + (1.57837) * green_ + (-0.73191) * blue_;
-	Z = (-0.68202) * red_ + (0.77073) * green_ + (0.563320) * blue_;
-	
-	x = X / (X + Y + Z);
-	y = Y / (X + Y + Z);
-	
-	if( (X > 0) && ( Y > 0) && ( Z > 0) )
-	{
-		Serial.println("The x,y values are(");
-		Serial.print(x, 2);
-		Serial.print(" , ");
-		Serial.print(y, 2);
-		Serial.println(")");
-	}
-	else
-		Serial.println("Error: overflow!");
+void GroveColorSensor::calculateCoordinate() {
+    double X;
+    double Y;
+    double Z;
+    double x;
+    double y;
+
+    X = (-0.14282) * red_ + (1.54924) * green_ + (-0.95641) * blue_;
+    Y = (-0.32466) * red_ + (1.57837) * green_ + (-0.73191) * blue_;
+    Z = (-0.68202) * red_ + (0.77073) * green_ + (0.563320) * blue_;
+
+    x = X / (X + Y + Z);
+    y = Y / (X + Y + Z);
+
+    if ((X > 0) && (Y > 0) && (Z > 0)) {
+        Serial.println("The x,y values are(");
+        Serial.print(x, 2);
+        Serial.print(" , ");
+        Serial.print(y, 2);
+        Serial.println(")");
+    } else {
+        Serial.println("Error: overflow!");
+    }
 }

+ 49 - 50
GroveColorSensor.h

@@ -1,68 +1,67 @@
-/****************************************************************************/	
+/****************************************************************************/
 //	Hardware: Grove - I2C Color Sensor
 //  Arduino IDE: Arduino-1.6
-//  
+//
 //  Refactored version of the library by FrankieChu - www.seeedstudio.com
-//	
+//
 /******************************************************************************/
 
 #ifndef GROVECOLORSENSOR
 #define GROVECOLORSENSOR
 
 #if defined(ARDUINO) && ARDUINO >= 100
-  #include "Arduino.h"
+    #include "Arduino.h"
 #else
-  #include "WProgram.h"
+    #include "WProgram.h"
 #endif
 #include <Registers.h>
 
-class GroveColorSensor
-{
-public:
+class GroveColorSensor {
+  public:
 
-	// Color Sensor LED Status
-	int ledStatus;
-	// Default constructor
-	GroveColorSensor();
-	// Constructor with parameters
-	GroveColorSensor(
-		  const int& triggerMode
-		, const int& interruptSource
-		, const int& interruptMode
-		, const int& gainAndPrescaler
-		, const int& sensorAddress);
+    // Color Sensor LED Status
+    int ledStatus;
+    // Default constructor
+    GroveColorSensor();
+    // Constructor with parameters
+    GroveColorSensor(
+        const int& triggerMode
+        , const int& interruptSource
+        , const int& interruptMode
+        , const int& gainAndPrescaler
+        , const int& sensorAddress);
+
+    void readRGB();
+    void readRGB(int* red, int* green, int* blue);
+    void calculateCoordinate();
+    void clearInterrupt();
+
+  private:
+
+    // Set trigger mode. Including free mode, manually mode, single synchronization mode or so.
+    void setTimingReg();
+    // Set interrupt source
+    void setInterruptSourceReg();
+    // Set interrupt mode
+    void setInterruptControlReg();
+    // Set gain value and pre-scaler value
+    void setGain();
+    // Start ADC of the colour sensor
+    void setEnableADC();
+
+    // Used for storing the colour data
+    int readingdata_[8];
+    int green_;
+    int red_;
+    int blue_;
+    int clear_;
+
+    int triggerMode_;
+    int interruptSource_;
+    int interruptMode_;
+    int gainAndPrescaler_;
+    int sensorAddress_;
 
-	void readRGB();
-	void readRGB(int *red, int *green, int *blue);
-	void calculateCoordinate();
-	void clearInterrupt();
-	
-private:	 
-	 
-	// Set trigger mode. Including free mode, manually mode, single synchronization mode or so.
-	void setTimingReg();
-	// Set interrupt source
-	void setInterruptSourceReg();
-	// Set interrupt mode
-	void setInterruptControlReg();
-	// Set gain value and pre-scaler value
-	void setGain();
-	// Start ADC of the colour sensor
-	void setEnableADC();
-	
-	// Used for storing the colour data
-	int readingdata_[8];
-	int green_;
-	int red_;
-	int blue_;
-	int clear_;
-	
-	int triggerMode_;	
-	int interruptSource_;
-	int interruptMode_;
-	int gainAndPrescaler_;
-	int sensorAddress_;
-	
 };
 
 #endif

+ 5 - 5
Registers.h

@@ -1,8 +1,8 @@
 #ifndef GROVECOLORSENSORREG
 #define GROVECOLORSENSORREG
 
-//the I2C address for the color sensor 
-#define COLOR_SENSOR_ADDR  0x39 
+//the I2C address for the color sensor
+#define COLOR_SENSOR_ADDR  0x39
 #define REG_CTL 0x80
 #define REG_TIMING 0x81
 #define REG_INT 0x82
@@ -14,7 +14,7 @@
 #define REG_HIGH_THRESH_LOW_BYTE 0x8A
 #define REG_HIGH_THRESH_HIGH_BYTE 0x8B
 //The REG_BLOCK_READ and REG_GREEN_LOW direction are the same
-#define REG_BLOCK_READ 0xD0 
+#define REG_BLOCK_READ 0xD0
 #define REG_GREEN_LOW 0xD0
 #define REG_GREEN_HIGH 0xD1
 #define REG_RED_LOW 0xD2
@@ -32,13 +32,13 @@
 #define INTEG_MODE_MANUAL 0x10
 #define INTEG_MODE_SYN_SINGLE 0x20
 #define INTEG_MODE_SYN_MULTI 0x30
- 
+
 #define INTEG_PARAM_PULSE_COUNT1 0x00
 #define INTEG_PARAM_PULSE_COUNT2 0x01
 #define INTEG_PARAM_PULSE_COUNT4 0x02
 #define INTEG_PARAM_PULSE_COUNT8 0x03
 
-//Interrupt Control Register 
+//Interrupt Control Register
 #define INTR_STOP 40
 #define INTR_DISABLE 0x00
 #define INTR_LEVEL 0x10

+ 7 - 10
Utilities.h

@@ -6,22 +6,19 @@
 #define SELECT_PIN1 12
 #define SELECT_PIN2 11
 
-void setupMuxPins()
-{
+void setupMuxPins() {
     pinMode(SELECT_PIN1, OUTPUT);
     pinMode(SELECT_PIN2, OUTPUT);
 }
 
-void ActivateLeftColorSensor()
-{
-    digitalWrite(SELECT_PIN2,LOW);
-    digitalWrite(SELECT_PIN1,HIGH);
+void ActivateLeftColorSensor() {
+    digitalWrite(SELECT_PIN2, LOW);
+    digitalWrite(SELECT_PIN1, HIGH);
 }
 
-void ActivateRightColorSensor()
-{
-    digitalWrite(SELECT_PIN2,LOW);
-    digitalWrite(SELECT_PIN1,LOW);
+void ActivateRightColorSensor() {
+    digitalWrite(SELECT_PIN2, LOW);
+    digitalWrite(SELECT_PIN1, LOW);
 }
 
 #endif

+ 49 - 52
examples/ColorSensorWithRGB_LED/ColorSensorWithRGB_LED.ino

@@ -1,31 +1,31 @@
 /*
- * Copyright (c) 2015 seeed technology inc.
- * Website    : www.seeed.cc
- * Author     : Wuruibin
- * Modified Time: June 2015
- * Description: This demo can measure the color chromaticity of ambient light or the color of objects,
- * 				and via Chainable RGB LED Grove displaying the detected color.
- * 
- * The MIT License (MIT)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
+    Copyright (c) 2015 seeed technology inc.
+    Website    : www.seeed.cc
+    Author     : Wuruibin
+    Modified Time: June 2015
+    Description: This demo can measure the color chromaticity of ambient light or the color of objects,
+  				and via Chainable RGB LED Grove displaying the detected color.
+
+    The MIT License (MIT)
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
 
 #include <Wire.h>
 #include <GroveColorSensor.h>
@@ -37,32 +37,29 @@
 
 ChainableLED leds(CLK_PIN, DATA_PIN, NUM_LEDS);
 
-void setup()
-{
-	Serial.begin(9600);
-	Wire.begin();
+void setup() {
+    Serial.begin(9600);
+    Wire.begin();
 }
 
-void loop()
-{
+void loop() {
     int red, green, blue;
-	GroveColorSensor colorSensor;
-	colorSensor.ledStatus = 1;							// When turn on the color sensor LED, ledStatus = 1; When turn off the color sensor LED, ledStatus = 0.
-	while(1)
-	{
-		colorSensor.readRGB(&red, &green, &blue);		//Read RGB values to variables.
-		delay(300);
-		Serial.print("The RGB value are: RGB( ");
-		Serial.print(red,DEC);
-		Serial.print(", ");
-		Serial.print(green,DEC);
-		Serial.print(", ");
-		Serial.print(blue,DEC);
-	    Serial.println(" )");
-		colorSensor.clearInterrupt();
-		for(int i = 0; i<NUM_LEDS; i++)
-		{
-			leds.setColorRGB(i, red, green, blue);
-		}
-	}
+    GroveColorSensor colorSensor;
+    colorSensor.ledStatus =
+        1;							// When turn on the color sensor LED, ledStatus = 1; When turn off the color sensor LED, ledStatus = 0.
+    while (1) {
+        colorSensor.readRGB(&red, &green, &blue);		//Read RGB values to variables.
+        delay(300);
+        Serial.print("The RGB value are: RGB( ");
+        Serial.print(red, DEC);
+        Serial.print(", ");
+        Serial.print(green, DEC);
+        Serial.print(", ");
+        Serial.print(blue, DEC);
+        Serial.println(" )");
+        colorSensor.clearInterrupt();
+        for (int i = 0; i < NUM_LEDS; i++) {
+            leds.setColorRGB(i, red, green, blue);
+        }
+    }
 }

+ 20 - 22
examples/GroveColorSensorDemo/GroveColorSensorDemo.ino

@@ -2,28 +2,26 @@
 //#include <math.h>
 #include <GroveColorSensor.h>
 
-void setup()
-{
-	Serial.begin(9600);
-	Wire.begin();
+void setup() {
+    Serial.begin(9600);
+    Wire.begin();
 }
 
-void loop()
-{
-	int red, green, blue;
-	GroveColorSensor colorSensor;
-	colorSensor.ledStatus = 1;							// When turn on the color sensor LED, ledStatus = 1; When turn off the color sensor LED, ledStatus = 0.
-	while(1)
-	{
-		colorSensor.readRGB(&red, &green, &blue);		//Read RGB values to variables.
-		delay(300);
-		Serial.print("The RGB value are: RGB( ");
-		Serial.print(red,DEC);
-		Serial.print(", ");
-		Serial.print(green,DEC);
-		Serial.print(", ");
-		Serial.print(blue,DEC);
-	    Serial.println(" )");
-		colorSensor.clearInterrupt();
-	}
+void loop() {
+    int red, green, blue;
+    GroveColorSensor colorSensor;
+    colorSensor.ledStatus =
+        1;							// When turn on the color sensor LED, ledStatus = 1; When turn off the color sensor LED, ledStatus = 0.
+    while (1) {
+        colorSensor.readRGB(&red, &green, &blue);		//Read RGB values to variables.
+        delay(300);
+        Serial.print("The RGB value are: RGB( ");
+        Serial.print(red, DEC);
+        Serial.print(", ");
+        Serial.print(green, DEC);
+        Serial.print(", ");
+        Serial.print(blue, DEC);
+        Serial.println(" )");
+        colorSensor.clearInterrupt();
+    }
 }

+ 33 - 35
examples/MUXandTwoSensorsDemo/MUXandTwoSensorsDemo.ino

@@ -1,7 +1,7 @@
-/****************************************************************************/    
+/****************************************************************************/
 //    Hardware: Grove - I2C Color Sensor
 //    Arduino IDE: Arduino-1.6
-//    
+//
 //    Author: Adrian Cotfas
 //    Based on the library by FrankieChu - www.seeedstudio.com
 //
@@ -44,40 +44,38 @@
 GroveColorSensor leftColorSensor;
 GroveColorSensor rightColorSensor;
 
-void setup()
-{
-  setupMuxPins();
-  Serial.begin(SERIAL_PORT_SPEED);
-  Wire.begin();
+void setup() {
+    setupMuxPins();
+    Serial.begin(SERIAL_PORT_SPEED);
+    Wire.begin();
 }
 
-void loop()
-{
-  int leftRed, leftGreen, leftBlue;
-  int rightRed, rightGreen, rightBlue;
-  ActivateLeftColorSensor();
-  leftColorSensor.readRGB(&leftRed, &leftGreen, &leftBlue);
-  delay(300);
-  Serial.println("Left: RGB( ");
-  Serial.print(leftRed,DEC);
-  Serial.print(", ");
-  Serial.print(leftGreen,DEC);
-  Serial.print(", ");
-  Serial.print(leftBlue,DEC);
-  Serial.println(" )");
-  leftColorSensor.clearInterrupt();
+void loop() {
+    int leftRed, leftGreen, leftBlue;
+    int rightRed, rightGreen, rightBlue;
+    ActivateLeftColorSensor();
+    leftColorSensor.readRGB(&leftRed, &leftGreen, &leftBlue);
+    delay(300);
+    Serial.println("Left: RGB( ");
+    Serial.print(leftRed, DEC);
+    Serial.print(", ");
+    Serial.print(leftGreen, DEC);
+    Serial.print(", ");
+    Serial.print(leftBlue, DEC);
+    Serial.println(" )");
+    leftColorSensor.clearInterrupt();
+
+    ActivateRightColorSensor();
+    rightColorSensor.readRGB(&rightRed, &rightGreen, &rightBlue);
+    delay(300);
+    Serial.println("Right: RGB( ");
+    Serial.print(rightRed, DEC);
+    Serial.print(", ");
+    Serial.print(rightGreen, DEC);
+    Serial.print(", ");
+    Serial.print(rightBlue, DEC);
+    Serial.println(" )");
 
-  ActivateRightColorSensor();
-  rightColorSensor.readRGB(&rightRed, &rightGreen, &rightBlue);
-  delay(300);
-  Serial.println("Right: RGB( ");
-  Serial.print(rightRed,DEC);
-  Serial.print(", ");
-  Serial.print(rightGreen,DEC);
-  Serial.print(", ");
-  Serial.print(rightBlue,DEC);
-  Serial.println(" )");
-  
-  rightColorSensor.clearInterrupt();
-  delay(1000);
+    rightColorSensor.clearInterrupt();
+    delay(1000);
 }