-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
266 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
실행전 설치 사항 | ||
1. qfirmata 소스를 받아서 빌드 한다. | ||
2. 생성된 라이브러리 파일을 qt가 설치된 곳의 qml 폴더에 위치 시킨다. | ||
3. live coding 을 위해서 qmllivebench 를 사용하는 경우 qmllivebench 내의 설정에서 impport 를 추가해줌 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#define trigPin 11 | ||
#define echoPin 12 | ||
#define RedLed 13 | ||
#define greenLed 3 | ||
|
||
void setup() { | ||
Serial.begin (9600); | ||
pinMode(trigPin, OUTPUT); | ||
pinMode(echoPin, INPUT); | ||
pinMode(RedLed, OUTPUT); | ||
pinMode(greenLed, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
digitalWrite(trigPin, LOW); | ||
delayMicroseconds(5); | ||
digitalWrite(trigPin, HIGH); | ||
delayMicroseconds(10); | ||
digitalWrite(trigPin, LOW); | ||
|
||
// 30 msec time out in sensor spec | ||
float duration = pulseIn(echoPin, HIGH, 30000); | ||
int distance = int(duration * 0.034 / 2); | ||
|
||
if (distance < 4) { // This is where the RED LED On/Off happens | ||
digitalWrite(RedLed, HIGH); // When the Red condition is met, the Green LED should turn off | ||
digitalWrite(greenLed, LOW); | ||
} | ||
else { | ||
digitalWrite(RedLed, LOW); | ||
digitalWrite(greenLed, HIGH); | ||
} | ||
|
||
Serial.print(distance); | ||
Serial.println(" cm"); | ||
|
||
|
||
// if (distance >= 200 || distance <= 0){ | ||
// Serial.println(distance); | ||
// Serial.println(duration); | ||
// } | ||
// else { | ||
// Serial.print(distance); | ||
// Serial.println(" cm"); | ||
// } | ||
delay(30); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <Firmata.h> | ||
|
||
#define trigPin 11 | ||
#define echoPin 12 | ||
#define RedLed 13 | ||
#define greenLed 3 | ||
#define pingPin 7 | ||
|
||
void setup() { | ||
Serial.begin (115200); | ||
pinMode(trigPin, OUTPUT); | ||
pinMode(echoPin, INPUT); | ||
pinMode(RedLed, OUTPUT); | ||
pinMode(greenLed, OUTPUT); | ||
Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); | ||
Firmata.begin(115200); | ||
} | ||
|
||
void loop() | ||
{ | ||
while (Firmata.available()) { | ||
Firmata.processInput(); | ||
} | ||
|
||
int distance = computeDistance(); | ||
|
||
// Serial.print(distance); | ||
// Serial.println(" cm"); | ||
Firmata.sendAnalog(pingPin, distance); | ||
} | ||
|
||
|
||
long computeDistance() | ||
{ | ||
digitalWrite(trigPin, LOW); | ||
delayMicroseconds(2); | ||
digitalWrite(trigPin, HIGH); | ||
delayMicroseconds(10); | ||
digitalWrite(trigPin, LOW); | ||
|
||
// 30 msec time out in sensor spec | ||
long duration = pulseIn(echoPin, HIGH, 30000); | ||
int distance = microsecondsToCentimeters(duration); | ||
|
||
if (distance < 4) { // This is where the RED LED On/Off happens | ||
digitalWrite(RedLed, HIGH); // When the Red condition is met, the Green LED should turn off | ||
digitalWrite(greenLed, LOW); | ||
} | ||
else { | ||
digitalWrite(RedLed, LOW); | ||
digitalWrite(greenLed, HIGH); | ||
} | ||
// it's timeout(30us) when the distance is 0, so dont need to delay | ||
if ( distance != 0 ) | ||
delay(30); | ||
|
||
return distance; | ||
} | ||
long microsecondsToInches(long microseconds) | ||
{ | ||
// According to Parallax's datasheet for the PING))), there are | ||
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per | ||
// second). This gives the distance travelled by the ping, outbound | ||
// and return, so we divide by 2 to get the distance of the obstacle. | ||
// See: [http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf](http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf) | ||
return microseconds / 74 / 2; | ||
} | ||
|
||
long microsecondsToCentimeters(long microseconds) | ||
{ | ||
// The speed of sound is 340 m/s or 29 microseconds per centimeter. | ||
// The ping travels out and back, so to find the distance of the | ||
// object we take half of the distance travelled. | ||
return microseconds / 29 / 2; | ||
} | ||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import QtQuick 2.7 | ||
import QtQuick.Controls 2.0 | ||
import QtQuick.Layouts 1.3 | ||
|
||
Rectangle{ | ||
color: "black" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import QtQuick 2.7 | ||
import QtQuick.Controls 2.0 | ||
import QtQuick.Layouts 1.3 | ||
import "firmata" | ||
|
||
Rectangle{ | ||
id: main | ||
anchors.fill: parent | ||
PortSelector { | ||
id: port | ||
anchors.top: main.top | ||
height:40 | ||
width: main.width | ||
Rectangle { | ||
visible: false | ||
anchors.fill: parent | ||
color: "black" | ||
opacity: 0.5 | ||
} | ||
|
||
Component.onCompleted: { | ||
|
||
} | ||
onDataReceived: { | ||
dataUpdate(rawValue) | ||
} | ||
|
||
|
||
|
||
} | ||
QChartGallery{ | ||
id: gallery | ||
anchors.left: main.left | ||
anchors.top: port.bottom | ||
width: main.width | ||
height: main.height - port.height | ||
|
||
Rectangle{ | ||
visible: false | ||
anchors.fill: parent | ||
color: "green" | ||
opacity: 0.5 | ||
} | ||
} | ||
Timer { | ||
id: timer | ||
interval: 100 | ||
running: false | ||
repeat: true | ||
onTriggered: { | ||
var d = new Date() | ||
gallery.chart_line_data.ChartLineData["labels"].shift() | ||
gallery.chart_line_data.ChartLineData["labels"].push(d.getSeconds() + "." + d.getMilliseconds() ) | ||
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].shift() | ||
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].push(Math.floor(Math.random() * 400 +1 ).toString()) | ||
gallery.chart_line_data.ChartLineData["datasets"][1]["data"].shift() | ||
gallery.chart_line_data.ChartLineData["datasets"][1]["data"].push(Math.floor(Math.random() * 400 +1 ).toString()) | ||
gallery.chart_line.repaint() | ||
|
||
} | ||
} | ||
function dataUpdate(rawValue){ | ||
var d = new Date() | ||
gallery.chart_line_data.ChartLineData["labels"].shift() | ||
gallery.chart_line_data.ChartLineData["labels"].push(d.getSeconds() + "." + d.getMilliseconds() ) | ||
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].shift() | ||
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].push(rawValue.toString()) | ||
// gallery.chart_line_data.ChartLineData["datasets"][1]["data"].shift() | ||
// gallery.chart_line_data.ChartLineData["datasets"][1]["data"].push(Math.floor(Math.random() * 400 +1 ).toString()) | ||
gallery.chart_line.repaint() | ||
|
||
} | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import QtQuick 2.7 | ||
import QtQuick.Controls 2.0 | ||
import QtQuick.Layouts 1.3 | ||
Rectangle{ | ||
color: "red" | ||
anchors.fill: parent | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,61 @@ | ||
import QtQuick 2.5 | ||
import QtQuick.Controls 1.4 | ||
import QtQuick.Layouts 1.2 | ||
import "firmata" | ||
import QtQuick 2.7 | ||
import QtQuick.Controls 2.0 | ||
import QtQuick.Layouts 1.3 | ||
import QtQuick.Extras 1.4 | ||
|
||
ApplicationWindow{ | ||
Rectangle{ | ||
id: main | ||
visible: true | ||
width: 640 | ||
height: 480 | ||
title: qsTr("Hello World") | ||
PortSelector { | ||
id: port | ||
anchors.top: main.top | ||
height:40 | ||
width: main.width | ||
Rectangle { | ||
visible: false | ||
anchors.fill: parent | ||
color: "black" | ||
opacity: 0.5 | ||
} | ||
anchors.fill: parent | ||
|
||
Component.onCompleted: { | ||
color: "blue" | ||
|
||
ListModel { | ||
id: viewModel | ||
ListElement { | ||
qmlName: "InitWnd.qml" | ||
} | ||
onDataReceived: { | ||
dataUpdate(rawValue) | ||
ListElement { | ||
qmlName: "ProcessingWnd.qml" | ||
} | ||
|
||
|
||
|
||
} | ||
QChartGallery{ | ||
id: gallery | ||
anchors.left: main.left | ||
anchors.top: port.bottom | ||
width: main.width | ||
height: main.height - port.height | ||
|
||
Rectangle{ | ||
visible: false | ||
anchors.fill: parent | ||
color: "green" | ||
opacity: 0.5 | ||
ListElement { | ||
qmlName: "StandbyWnd.qml" | ||
} | ||
} | ||
Timer { | ||
id: timer | ||
interval: 100 | ||
running: false | ||
repeat: true | ||
onTriggered: { | ||
var d = new Date() | ||
gallery.chart_line_data.ChartLineData["labels"].shift() | ||
gallery.chart_line_data.ChartLineData["labels"].push(d.getSeconds() + "." + d.getMilliseconds() ) | ||
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].shift() | ||
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].push(Math.floor(Math.random() * 400 +1 ).toString()) | ||
gallery.chart_line_data.ChartLineData["datasets"][1]["data"].shift() | ||
gallery.chart_line_data.ChartLineData["datasets"][1]["data"].push(Math.floor(Math.random() * 400 +1 ).toString()) | ||
gallery.chart_line.repaint() | ||
Component { | ||
id: delegate | ||
Loader { | ||
id: wnd | ||
source: qmlName | ||
width: parent.width / 10 * 8 | ||
height: parent.height / 10 * 8 | ||
z: wnd.PathView.isCurrentItem ? 0 : -1 | ||
opacity: wnd.PathView.isCurrentItem ? 1: 0.5 | ||
scale: wnd.PathView.isCurrentItem ? 1: 0.5 | ||
|
||
} | ||
} | ||
function dataUpdate(rawValue){ | ||
var d = new Date() | ||
gallery.chart_line_data.ChartLineData["labels"].shift() | ||
gallery.chart_line_data.ChartLineData["labels"].push(d.getSeconds() + "." + d.getMilliseconds() ) | ||
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].shift() | ||
gallery.chart_line_data.ChartLineData["datasets"][0]["data"].push(rawValue.toString()) | ||
// gallery.chart_line_data.ChartLineData["datasets"][1]["data"].shift() | ||
// gallery.chart_line_data.ChartLineData["datasets"][1]["data"].push(Math.floor(Math.random() * 400 +1 ).toString()) | ||
gallery.chart_line.repaint() | ||
// Rectangle{ | ||
// anchors.left: parent.left | ||
// width: 580 | ||
// height: 180 | ||
// color: "yellow" | ||
// opacity: 0.5 | ||
// z: 100 | ||
|
||
// } | ||
|
||
PathView { | ||
id: pathView | ||
anchors.fill: parent | ||
model: viewModel | ||
delegate: delegate | ||
path: Path { | ||
startX: parent.width /2 | ||
startY: parent.height /2 | ||
PathQuad { x: parent.width / 2; y: -parent.height * 0.1; controlX: parent.width * 1.1 ; controlY: parent.height/2 } | ||
PathQuad { x: parent.width / 2; y: parent.height /2; controlX: -parent.width * 0.1; controlY: parent.height/2 } | ||
} | ||
} | ||
} | ||
|
||
|
||
// footer: TabBar { | ||
// id: tabBar | ||
// currentIndex: swipeView.currentIndex | ||
// TabButton { | ||
// text: qsTr("First") | ||
// } | ||
// TabButton { | ||
// text: qsTr("Second") | ||
// } | ||
// } |