Skip to content

Instantly share code, notes, and snippets.

View yostane's full-sized avatar

Yassine Benabbas yostane

View GitHub Profile
func handleNilWithoutGuardMethod1(str: String?){
if str == nil {
print("str is nil")
return
}
let s = str!
print("s in not nill here \(s)")
//do other things here
}
func handleNilWithoutGuardMethod2(str: String?){
if let s = str {
print("s in not nil here \(s)")
//do other things here
}else{
print("str is nil")
}
}
handleNilWithoutGuardMethod2(str: nil)
handleNilWithoutGuardMethod2(str: "hello")
func guardMe(str: String?){
guard let s = str else{
print("str is nil")
return
}
print("s in not nil here \(s)")
//do other things here
}
guardMe(str: nil)
func guardMe2(str: String?){
guard let s = str, s == "hello" else{
print("str is nil or not equal to hello")
return
}
print("s is equal to hello \(s)")
//do other things here
}
guardMe2(str: nil)
while (mySerial.available()) {
Serial.write(mySerial.read());
}
void sendCommand(const char * command){
  Serial.print("Command send :");
  Serial.println(command);
  mySerial.println(command);
  //wait some time
  delay(100);
 
  char reply[100];
  int i = 0;
  while (mySerial.available()) {
void setup() {
// put your setup code here, to run once:
mySerial.begin(9600);
Serial.begin(9600);
sendCommand("AT");
sendCommand("AT+ROLE0");
sendCommand("AT+UUID0xFFE0");
sendCommand("AT+CHAR0xFFE1");
sendCommand("AT+NAMEbluino");
void readSerial(){
char reply[50];
int i = 0;
while (mySerial.available()) {
reply[i] = mySerial.read();
i += 1;
}
//end the string
reply[i] = '\0';
if(strlen(reply) > 0){
void loop() {
readSerial();
delay(500);
}
void writeToBLE(char value) {
Serial.print("Writing hex :");
Serial.println(value, HEX);
mySerial.write(value);
}