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
| let dwi = DispatchWorkItem { | |
| for i in 1...5 { | |
| print("DispatchWorkItem \(i)") | |
| } | |
| } | |
| //perform on the current thread | |
| dwi.perform() | |
| //perpform on the global queue | |
| DispatchQueue.global().async(execute: dwi) |
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
| let dq = DispatchQueue(label: "my dispatch queue") | |
| dq.async { | |
| print ("hello") | |
| } |
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
| DispatchQueue.concurrentPerform(iterations: 5) { (i) in | |
| print(i) | |
| } |
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
| DispatchQueue.main.async { | |
| for i in 1...5 { | |
| print("main async \(i)") | |
| } | |
| } |
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
| DispatchQueue.global(qos: .background).async { | |
| for i in 1...5 { | |
| print("global async \(i)") | |
| } | |
| } | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| for i in 1...5 { | |
| print("global async 2 \(i)") | |
| } |
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
| //two concurrent loops | |
| DispatchQueue.global().async { | |
| for i in 1...5 { | |
| print("global async \(i)") | |
| } | |
| } | |
| DispatchQueue.global().async { | |
| for i in 1...5 { | |
| print("global async 2 \(i)") | |
| } |
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
| void writeToBLE(const char *value) { | |
| Serial.print("Writing :"); | |
| Serial.println(value); | |
| mySerial.write(value, strlen(value)); | |
| } |
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
| char j = 0; | |
| void loop() { | |
| float temp = readTemperature(); | |
| char strFloat[20]; | |
| dtostrf(temp, 2, 2, strFloat); | |
| writeToBLE(strFloat); | |
| j += 1; | |
| delay(2000); | |
| } |
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
| float readTemperature() { | |
| int reading = analogRead(sensorPin); | |
| float voltage = (reading * aref_voltage) / 1024; | |
| Serial.print(voltage); | |
| Serial.println(" volts"); | |
| float temperatureC = voltage / 10 ; | |
| Serial.print(temperatureC); Serial.println(" degrees C"); | |
| float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; |
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
| char j = 0; | |
| void loop() { | |
| writeToBLE(j); | |
| j += 1; | |
| delay(500); | |
| } |