Qduino: Difference between revisions
Jump to navigation
Jump to search
(hellorld!) |
(push button blinky distance) |
||
Line 1: | Line 1: | ||
[[File:Qduino Mini Schematic.png]] | |||
<pre> | |||
#define trigPin 1 | |||
#define echoPin 0 | |||
// the setup function runs once when you press reset or power the board | |||
void setup() { | |||
// initialize digital pin LED_BUILTIN as an output. | |||
Serial.begin(9600); | |||
pinMode(trigPin, OUTPUT); | |||
pinMode(echoPin, INPUT); | |||
pinMode(10, OUTPUT); | |||
pinMode(2, OUTPUT); | |||
digitalWrite(2, LOW); | |||
pinMode(4, INPUT_PULLUP); | |||
} | |||
// the loop function runs over and over again forever | |||
void loop() { | |||
bool HIGH_LOW = digitalRead(4); | |||
digitalWrite(10, HIGH_LOW); | |||
digitalWrite(2, !HIGH_LOW); | |||
ping(); | |||
} | |||
void ping() { | |||
long duration, distance; | |||
digitalWrite(trigPin, LOW); // Added this line | |||
delayMicroseconds(2); // Added this line | |||
digitalWrite(trigPin, HIGH); | |||
// delayMicroseconds(1000); - Removed this line | |||
delayMicroseconds(10); // Added this line | |||
digitalWrite(trigPin, LOW); | |||
duration = pulseIn(echoPin, HIGH); | |||
distance = (duration/2) / 29.1; | |||
Serial.println(distance); | |||
} | |||
void blink() { | |||
digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level) | |||
digitalWrite(2, HIGH); | |||
delay(100); | |||
digitalWrite(2, LOW); | |||
delay(900); // wait for a second | |||
digitalWrite(10, LOW); // turn the LED off by making the voltage LOW | |||
delay(1000); | |||
} | |||
</pre> | |||
* https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Qduino_Mini_v14.pdf | * https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Qduino_Mini_v14.pdf | ||
* https://www.sparkfun.com/products/13614 | * https://www.sparkfun.com/products/13614 | ||
* https://www.hackster.io/team-qtechknow/qduino-mini-quickstart-guide-8b2d68 | * https://www.hackster.io/team-qtechknow/qduino-mini-quickstart-guide-8b2d68 |
Latest revision as of 00:00, 7 November 2024
#define trigPin 1 #define echoPin 0 // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. Serial.begin(9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(10, OUTPUT); pinMode(2, OUTPUT); digitalWrite(2, LOW); pinMode(4, INPUT_PULLUP); } // the loop function runs over and over again forever void loop() { bool HIGH_LOW = digitalRead(4); digitalWrite(10, HIGH_LOW); digitalWrite(2, !HIGH_LOW); ping(); } void ping() { long duration, distance; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); // delayMicroseconds(1000); - Removed this line delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; Serial.println(distance); } void blink() { digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(2, HIGH); delay(100); digitalWrite(2, LOW); delay(900); // wait for a second digitalWrite(10, LOW); // turn the LED off by making the voltage LOW delay(1000); }