- 
      
- 
        Save kyeshmz/ed601fc6f9e57a7da25b7e71e456479b to your computer and use it in GitHub Desktop. 
    test
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include "Particle.h" | |
| SYSTEM_MODE(MANUAL); | |
| SYSTEM_THREAD(ENABLED); | |
| // const size_t UART_TX_BUF_SIZE = 98; | |
| void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context); | |
| void leftDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context); | |
| void centerDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context); | |
| void rightDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context); | |
| const BleUuid serviceUuid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E"); | |
| const BleUuid txUuid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"); | |
| const BleUuid rxUuid("6E400003-B5A3-F393-E0A9-E50E24DCCA9E"); | |
| BleCharacteristic txCharacteristic("tx", BleCharacteristicProperty::NOTIFY, txUuid, serviceUuid); | |
| BleCharacteristic rxCharacteristic("rx", BleCharacteristicProperty::WRITE_WO_RSP, rxUuid, serviceUuid, onDataReceived, NULL); | |
| const BleUuid ledserviceUuid("6F500001-B5A3-F393-E0A9-E50E24DCCA9E"); | |
| const BleUuid leftUuid("6F500002-B5A3-F393-E0A9-E50E24DCCA9E"); | |
| const BleUuid centerUuid("6F500003-B5A3-F393-E0A9-E50E24DCCA9E"); | |
| const BleUuid rightUuid("6F500004-B5A3-F393-E0A9-E50E24DCCA9E"); | |
| BleCharacteristic leftCharacteristic("left", BleCharacteristicProperty::WRITE_WO_RSP, leftUuid, ledserviceUuid, leftDataReceived, NULL); | |
| BleCharacteristic centerCharacteristic("center", BleCharacteristicProperty::WRITE_WO_RSP, centerUuid, ledserviceUuid, centerDataReceived, NULL); | |
| BleCharacteristic rightCharacteristic("right", BleCharacteristicProperty::WRITE_WO_RSP, rightUuid, ledserviceUuid, rightDataReceived, NULL); | |
| // // serial opens serial over usb | |
| // // serial1 opens serial over tx and rx pins | |
| // int ledPin = D2; | |
| // int centerPin = D3; | |
| int leftval=0, centerval=0, rightval=0; | |
| void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) { | |
| // Log.trace("Received data from: %02X:%02X:%02X:%02X:%02X:%02X:", peer.address()[0], peer.address()[1], peer.address()[2], peer.address()[3], peer.address()[4], peer.address()[5]); | |
| for (size_t ii = 0; ii < len; ii++) { | |
| //to serial monitor | |
| Serial.write(data[ii]); | |
| //to the interposer | |
| Serial1.write(data[ii]); | |
| } | |
| } | |
| void leftDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) { | |
| for (size_t ii = 0; ii < len; ii++) { | |
| uint8_t d = data[ii]; | |
| leftval = d; | |
| Serial.println(d); | |
| } | |
| } | |
| void centerDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) { | |
| for (size_t ii = 0; ii < len; ii++) { | |
| uint8_t d = data[ii]; | |
| centerval = d; | |
| Serial.println(d); | |
| } | |
| } | |
| void rightDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) { | |
| for (size_t ii = 0; ii < len; ii++) { | |
| uint8_t d = data[ii]; | |
| rightval = d; | |
| Serial.println(d); | |
| } | |
| } | |
| // // Serial and Serial1 | |
| // // This is TX and RX for UART serial | |
| // // Serial is RX and Serial1 is TX | |
| // // RX means serial data received into the device | |
| // // TX means serial data transmitted from the device | |
| int leftLed = D2; | |
| int centerLed = D3; | |
| int rightLed = D4; | |
| void setup() { | |
| //set LED | |
| pinMode(leftLed, OUTPUT); | |
| pinMode(centerLed, OUTPUT); | |
| pinMode(rightLed, OUTPUT); | |
| Serial.begin(115200); | |
| Serial.println("AltSoftSerial Test Begin"); | |
| // Serial1 RX is connected to Arduino TX (1) | |
| // Serial2 TX is connected to Arduino RX (0) | |
| // Photon GND is connected to Arduino GND | |
| Serial1.begin(115200); | |
| Serial1.println("Hello World"); | |
| BLE.on(); | |
| BLE.addCharacteristic(txCharacteristic); | |
| BLE.addCharacteristic(rxCharacteristic); | |
| BLE.addCharacteristic(leftCharacteristic); | |
| BLE.addCharacteristic(centerCharacteristic); | |
| BLE.addCharacteristic(rightCharacteristic); | |
| //BLE.addCharacteristic(leftCharacteristic); | |
| BleAdvertisingData data; | |
| data.appendServiceUUID(serviceUuid); | |
| data.appendServiceUUID(ledserviceUuid); | |
| BLE.advertise(&data); | |
| //Serial1.write("g"); | |
| //Serial1.print("g"); | |
| } | |
| void loop() { | |
| // char c; | |
| // if (Serial.available()) { | |
| // c = Serial.read(); | |
| // Serial1.print(c); | |
| // } | |
| processBuffer(); | |
| // while (Serial1.available()) { | |
| // processBuffer(); | |
| // } | |
| // analogWrite(leftLed, leftval); | |
| // analogWrite(centerLed, centerval); | |
| // analogWrite(rightLed, rightval); | |
| } | |
| void processBuffer() { | |
| char c = Serial1.read(); | |
| digitalWrite(leftLed,HIGH); | |
| //only serial is okay | |
| //Serial.print(c); | |
| txCharacteristic.setValue(c); | |
| digitalWrite(leftLed,LOW); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
``
`void processBuffer() {
static int ledState = HIGH;
ledState = ledState == HIGH ? LOW : HIGH;
char c = Serial1.read();
digitalWrite(leftLed,ledState);
//only serial is okay
//Serial.print(c);
txCharacteristic.setValue(c);
}