Skip to content

Instantly share code, notes, and snippets.

View yostane's full-sized avatar

Yassine Benabbas yostane

View GitHub Profile
char j = 0;
void loop() {
writeToBLE(j);
j += 1;
delay(500);
}
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;
char j = 0;
void loop() {
float temp = readTemperature();
char strFloat[20];
dtostrf(temp, 2, 2, strFloat);
writeToBLE(strFloat);
j += 1;
delay(2000);
}
void writeToBLE(const char *value) {
Serial.print("Writing :");
Serial.println(value);
mySerial.write(value, strlen(value));
}
@yostane
yostane / dispatch1.swift
Created February 12, 2017 10:26
Two concurrent loops
//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)")
}
@yostane
yostane / dispatch2.swift
Created February 12, 2017 10:37
Two concurrent loops on different QoS global queues. A background one and UI one
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)")
}
@yostane
yostane / dispatch3.swift
Created February 12, 2017 11:32
main dispatch queue (does not work on playgrounds)
DispatchQueue.main.async {
for i in 1...5 {
print("main async \(i)")
}
}
@yostane
yostane / dispatch4.swift
Created February 12, 2017 11:36
conccurenly performs work items
DispatchQueue.concurrentPerform(iterations: 5) { (i) in
print(i)
}
@yostane
yostane / dispatch5.swift
Created February 12, 2017 11:43
creating a custom dispatch queue
let dq = DispatchQueue(label: "my dispatch queue")
dq.async {
print ("hello")
}
@yostane
yostane / dispatch6.swift
Created February 12, 2017 11:45
A dispatch work item encapsulates work
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)