CC2540

From ElectroDragon
Jump to: navigation, search

Schematic

Arduino Demo Code

//arduino uno wiring
//BLE4.0   UNO
//VCC----->3.3V
//GND----->GND
//EN------>GND
//RX------>TX
//TX------>RX
//BCTS(NC)
//BRTS---->GND
 
int LED = 13;
 
void setup()
{
	pinMode(LED,OUTPUT);
  	Serial.begin(115200);		// baudrate 115200
  	while (!Serial); // wait for serial port to connect. Needed for Leonardo only
}
 
void loop()
{
  if (Serial.available() > 0) {
    char inChar = (char)Serial.read(); 	//read serial port data read serial port data
    Serial.write(inChar);				//send back received data, if the phone app can read the return data means the communication is working well
 
    if(inChar == 'B'){
    	digitalWrite(LED,HIGH);			//led on when press button B
    }
    else if(inChar == 'R'){
    	digitalWrite(LED,LOW);			//led off when press button R
    }
  }
}