2017年11月2日 星期四

VB研究小站-Visual BASIC(.NET)基礎語法 / Guide



VB研究小站-Visual BASIC(.NET)基礎語法 / Guide
小站的VB.NET入門文件 ... [回首頁]

小站的基礎語法是以概觀的方式介紹本工具的所有基本功能與能力,真正的用意並不是被用來作為新手教學,如果想要學習並閱讀新手教學相關文章,建議(1)到圖書館或是書店查閱相關書籍開始入門、(2)以小站的基礎語法作為日後備忘查閱。

入門基礎 / The first step

工具簡介VB2010VB2015
我的第一個程式
My first program
VB2005VB2010VB2015
基本資料輸出輸入介面
Input and output data
VB2005VB2010VB2015
基本的資料型態
Scalar data types
VB2005VB2010VB2015
基本的結構化資料型態
Structured data types
VB2005VB2010VB2015
基本資料的處理
Basic data handling
VB2005VB2010VB2015
運算子
Operators
VB2005VB2010VB2015
指標
Pointer
------
作業流程 / Control flow

副程式流程
Subroutine
VB2005VB2010VB2015
條件判斷流程
Branch of logic
VB2005VB2010VB2015
條件選擇流程
Branch of multiple ways
VB2005VB2010VB2015
限定範圍重複流程
Loop of a range
VB2005VB2010VB2015
限定條件重複流程
Loop of criteria
VB2005VB2010VB2015
限定元素重複流程
Loop of elements
VB2005VB2010VB2015
跳躍流程
Unconditional jumping
VB2005VB2010VB2015
錯誤捕捉流程
Exception capturing
VB2005VB2010VB2015
物件導向 / Object orientation

第一次實做類別
Create an object from a class
VB2005VB2010VB2015
類別成員
Class members
VB2005VB2010VB2015
連結介面
Interface and Connector
VB2005VB2010VB2015
建構子與解構子
Constructor and Destructor
VB2005VB2010VB2015
繼承/擴展
Inheritance / Extension
VB2005VB2010VB2015
世代交替
Alternation of generations
VB2005VB2010VB2015
多型
Polymorphism
VB2005VB2010VB2015
抽象類別
Abstract class
VB2005VB2010VB2015
資源空間

專案全域空間VB2005VB2010VB2015
命名空間VB2005VB2010VB2015
程式區塊空間VB2005VB2010VB2015
類別區塊空間VB2005VB2010VB2015
記憶保留空間VB2005VB2010VB2015
檔案操作

純文字循序存取VB2005VB2010VB2015
二進數循序存取VB2005VB2010VB2015
純文字隨機存取VB2005VB2010VB2015
二進數隨機存取VB2005VB2010VB2015
基礎檔案管理VB2005VB2010VB2015
資料應用

隨機數VB2005VB2010VB2015
三角函數VB2005VB2010VB2015
字串字元處裡VB2005VB2010VB2015
陣列元素巡迴VB2005VB2010VB2015
強化機制

物件回呼外部程式
Listener
VB2005VB2010VB2015
物件方法的委託VB2005VB2010VB2015
型別參數化VB2005VB2010VB2015
匿名副程式與 Lambda 演算
Anonymous Function & Lumbda
VB2010VB2015
閉包
Closure
VB2010VB2015


SVBR©8.0 VB研究小站 www.svbr8.url.tw @ Kaohsiung.Taiwan

[ VB2010 ] - 畫線與畫圓



源自於
http://www.svbr8.url.tw/Prg_Coding/VB/index_middle_drawing.php


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim BMP As Bitmap = New Bitmap(200, 100, Imaging.PixelFormat.Format32bppArgb)
        Dim g As Graphics = Graphics.FromImage(BMP)
        Dim f As Font = New Font(Me.Font.Name, 12, FontStyle.Bold)

        g.FillRectangle(Brushes.White, 0, 0, 200, 200)
        g.DrawRectangle(Pens.Black, 0, 0, 199, 99)

        g.DrawLine(Pens.Black, 1, 1, 200, 100)
        g.DrawLine(Pens.Black, 1, 1, 200, 50)
        g.DrawLine(Pens.Black, 1, 1, 100, 100)

        g.DrawEllipse(Pens.Black, 15, 5, 10, 12)
        g.DrawEllipse(Pens.Black, 30, 10, 20, 24)
        g.DrawEllipse(Pens.Black, 60, 20, 40, 48)
        g.DrawEllipse(Pens.Black, 120, 40, 80, 96)

        g.DrawString("S", f, Brushes.Red, 5, 55)
        g.DrawString("V", f, Brushes.Orange, 15, 55)
        g.DrawString("B", f, Brushes.Green, 25, 55)
        g.DrawString("R", f, Brushes.Blue, 35, 55)

        g.Dispose()
        Me.BackgroundImageLayout = ImageLayout.None
        Me.BackgroundImage = BMP

    End Sub

End Class

isual BASIC(.NET)影像繪製



VB研究小站-Visual BASIC(.NET)影像繪製
小站有關於VB的影像繪製範本 ... [回首頁]


基本繪圖 / Basic

繪製線條
Draw lines
VB2005VB2010VB2015
繪製多邊形
Draw polygons
VB2005VB2010VB2015
繪製矩形
Draw rectangles
VB2005VB2010VB2015
繪製橢圓形
Draw ellipses
VB2005VB2010VB2015
繪製圓形
Draw circles
VB2005VB2010Wait
繪製弧線
Draw arcs
VB2005VB2010Wait
繪製圖片
Draw images
VB2005VB2010Wait
畫線與畫圓VB2005VB2010VB2015
繪製哆啦A夢
Draw a Doraemon
VB2005VB2010VB2015
繪製10點10分的指針VB2005VB2010VB2015
繪製模擬光譜VB2005VB2010VB2015
文字抹上漸層色VB2005VB2010VB2015
函數繪製 / Function Graph

繪製多項式函數VB2005VB2010VB2015
繪製正弦波VB2005VB2010VB2015
繪製斜橢圓VB2005VB2010VB2015
函數圖表 / Chart

繪製XY散佈圖VB2005VB2010VB2015
繪製折線圖VB2005VB2010VB2015
繪製長條圖VB2005VB2010VB2015

[ VB2010 ] - 繪製線條


源自於
http://www.svbr8.url.tw/Prg_Coding/VB/Middle/Drawing/VB_00_00_VB2010/doc.php


Graphics.DrawLine(Pen物件, X1, Y1, X2, Y2)


Public Class Form1
    Dim Painting As Bitmap

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Painting = New Bitmap(200, 100)
        Dim G As Graphics = Graphics.FromImage(Painting)
        Dim Idx As Integer

        For Idx = 1 To 100 Step 3
            G.DrawLine(Pens.White, 0, Idx, 200, Idx)
            G.DrawLine(Pens.Gray, 0, Idx + 1, 200, Idx + 1)
            G.DrawLine(Pens.Black, 0, Idx + 2, 200, Idx + 2)
        Next

        G.DrawLine(New Pen(Brushes.Red, 7), 30, 1, 10, 100)
        G.DrawLine(New Pen(Brushes.Orange, 6), 27, 1, 20, 100)
        G.DrawLine(New Pen(Brushes.Yellow, 5), 24, 1, 30, 100)
        G.DrawLine(New Pen(Brushes.Green, 4), 21, 1, 40, 100)
        G.DrawLine(New Pen(Brushes.Blue, 3), 18, 1, 50, 100)
        G.DrawLine(New Pen(Brushes.Indigo, 2), 15, 1, 60, 100)
        G.DrawLine(Pens.Purple, 12, 1, 70, 100)
        G.DrawLine(Pens.Black, 9, 1, 80, 100)
        G.DrawLine(Pens.Gray, 6, 1, 90, 100)
        G.DrawLine(Pens.White, 3, 1, 100, 100)

        Me.BackgroundImageLayout = ImageLayout.None
        Me.BackgroundImage = Painting
    End Sub

End Class

2017年10月30日 星期一

DHT11 MQTT publisher & Subscriber + Blynk (2 WIFI ssid password)









/*  Publisher Humidity , Temperature , Humidity & Temperature  3 item data
 *  Subscribe 3 data by Arduino program Subscribe & Blynk APP
 * 
 * Use NodeMCU to drive DHT11 and send temperature/humidity value to MQTT server
 * CopyRight www.osoyoo.com
 * Software:
 * Arduino IDE(version 1.6.4+)
 * ESP8266 Board Package and the Serial Port Driver
 * MQTT Clirnt (MQTTBox here)
 * Arduino library: PubSubClient
 * Arduino library:DHT
 * Connection
 * NodeMCU DHT11 sensor
 * 3.3v    VCC
 * D3      DATA
 * GND     Ground
 *   *
 */

//=====Blynk=================================
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>   //including the library of SimpleTimer
//=====Blynk=================================
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <dht.h>
dht DHT;
// Define NodeMCU D3 pin to as temperature data pin of  DHT11
#define DHT11_PIN D3

//========================LED====================
#define LED     D0        // Led in NodeMCU at pin GPIO16 (D0).
#define BRIGHT    350*2     //max led intensity (1-500)
#define INHALE    1250*2    //Inhalation time in milliseconds.
#define PULSE     INHALE*1000/BRIGHT
#define REST      1000    //Rest Between Inhalations.
//========================LED====================

// Update these with values suitable for your network.
//const char* ssid = "******";//put your own wifi ssid here
//const char* password = "******";// put your wifi password here

const char* ssid = "My ASUS";//put your wifi ssid here
const char* password = "alex9981" ;//put your wifi password here 

const char* ssid2 = "74170287";//put your wifi ssid here
const char* password2 = "24063173" ;//put your wifi password here 

//========================================================
SimpleTimer timer;
//char auth[] = "Your Auth. Key";            // You should get Auth Token in the Blynk App.
                                           // Go to the Project Settings (nut icon).
const char auth[] = "bd2c91fd614b4d478c780881d06b75b6";
float t , t1;                                   // Declare the variables
float h , h1;
//========================================================

const char* mqtt_server = "broker.mqtt-dashboard.com";
//const char* mqtt_server = "iot.eclipse.org";

WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;

void setup_wifi() {
   delay(100);
  // We start by connecting to a WiFi network
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
      delay(500);
      Serial.print(".");
    }
  randomSeed(micros());
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println("MQTT-DHT11-Testing");
 
}

void callback(char* topic, byte* payload, unsigned int length)    // call back "Alex9ufo-DHT3-Command"
{
  Serial.print("Command is : [");
  Serial.print(topic);
  int p =(char)payload[0]-'0';
  int chk = DHT.read11(DHT11_PIN);
  // if MQTT comes a 0 message, show humidity
  if(p==0)
  {
    Serial.println("to show humidity!]");
    Serial.print(" Humidity is: " );
    Serial.print(DHT.humidity, 1);
    Serial.println('%');
    //ramp decreasing intensity, Exhalation (half time):
    for (int i=BRIGHT-1;i>0;i--){
      digitalWrite(LED, LOW);          // turn the LED on.
      delayMicroseconds(i*10);          // wait
      digitalWrite(LED, HIGH);         // turn the LED off.
      delayMicroseconds(PULSE-i*10);  // wait
      i--;
      delay(0);                        //to prevent watchdog firing.
    }
  digitalWrite(LED, HIGH);
  }
  // if MQTT comes a 1 message, show temperature
  if(p==1)
  {
  // digitalWrite(BUILTIN_LED, HIGH);
   Serial.println(" is to show temperature!] ");
   int chk = DHT.read11(DHT11_PIN);
   Serial.print(" Temp is: " );
   Serial.print(DHT.temperature, 1);
   Serial.println(' C');

   //ramp increasing intensity, Inhalation:
   for (int i=1;i<BRIGHT;i++){
      digitalWrite(LED, LOW);          // turn the LED on.
      delayMicroseconds(i*10);         // wait
      digitalWrite(LED, HIGH);         // turn the LED off.
      delayMicroseconds(PULSE-i*10);   // wait
      delay(0);                        //to prevent watchdog firing.
    }
   digitalWrite(LED, LOW);
  }
  Serial.println();
 
} //end callback

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected())
  {
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
    //if you MQTT broker has clientID,username and password
    //please change following line to    if (client.connect(clientId,userName,passWord))
    if (client.connect(clientId.c_str()))
    {
      Serial.println("connected");
     //once connected to MQTT broker, subscribe command if any
      client.subscribe("Alex9ufo-DHT3-Command");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 6 seconds before retrying
      delay(6000);
    }
  }
} //end reconnect()

void setup() {
  pinMode(LED, OUTPUT);   // LED pin as output.
  //========Blynk==============
  Blynk.begin(auth, ssid2, password2);
  timer.setInterval(1000, sendUptime); 
  //========Blynk==============
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  int chk = DHT.read11(DHT11_PIN);
  Serial.print(" Starting Humidity: " );
  Serial.print(DHT.humidity, 1);
  Serial.println('%');
  Serial.print(" Starting Temparature ");
  Serial.print(DHT.temperature, 1);
  Serial.println('C');
}

void sendUptime()
{
   // 如果要取小數三位 *1000
   // double d1 = 30.745678;
   // double d2 = int(d1*1000+0.5)/1000; //30.746
 
  float h = (DHT.humidity);
  float h1=int(h*1000+0.5)/1000;
  float t = (DHT.temperature);
  float t1=int(t*1000+0.5)/1000;
 
  Blynk.virtualWrite(V0, t1);
  Blynk.virtualWrite(V1, h1);
}

void loop() {

  if (!client.connected()) {
    reconnect();
  }
  client.loop();
  long now = millis();
  // read DHT11 sensor every 6 seconds
  if (now - lastMsg > 6000) {
     digitalWrite(LED, !digitalRead(LED));
     lastMsg = now;
     int chk = DHT.read11(DHT11_PIN);

     String msg="";
     msg= msg+ DHT.temperature;
     char message[58];
     msg.toCharArray(message,58);   
     client.publish("alex9ufo-temp-RaspiData", message);

     msg="";
     msg= msg+ DHT.humidity;
     msg.toCharArray(message,58);   
     client.publish("alex9ufo-humi-RaspiData",message);

     msg="";
     msg= msg+ DHT.temperature;
     msg = msg+"," ;
     msg=msg+DHT.humidity ;
     msg.toCharArray(message,58);

    Serial.print(" Starting Temparature ");
    Serial.print(DHT.temperature, 1);
    Serial.print('C');
    Serial.print("    Starting Humidity: " );
    Serial.print(DHT.humidity, 1);
    Serial.println('%');
 
    Serial.println(message);
     //publish sensor data to MQTT broker
    client.publish("alex9ufo-DHT11-RaspiData", message);

  }
     //=========Blynk======================
    Blynk.run();
    timer.run();
 
}

2017年10月28日 星期六

NODEMCU (ESP32) Subscribing to MQTT 3-topic



#include <ESP8266WiFi.h>
#include <PubSubClient.h>

//const char* ssid = "yourNetworkName";
//const char* password =  "yourNetworkPassword";
const char* ssid = "My ASUS";
const char* password =  "alex9981";
//const char* mqttServer = "m11.cloudmqtt.com";
const char* mqttserver = "broker.mqtt-dashboard.com";
const int mqttPort = 1883;
//const char* mqttUser = "yourMQTTuser";
//const char* mqttPassword = "yourMQTTpassword";
const char* mqttUser = "";
const char* mqttPassword = "";

WiFiClient espClient;
PubSubClient client(espClient);

void callback(char* topic, byte* payload, unsigned int length) {

  Serial.print("Message arrived in topic: ");
  Serial.println(topic);

  Serial.print("Message:");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }

  Serial.println();
  Serial.println("-----------------------");

}

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
  Serial.println("Connected to the WiFi network");

  client.setServer(mqttserver, mqttPort);
  client.setCallback(callback);

  while (!client.connected()) {
    Serial.println("Connecting to MQTT...");

    if (client.connect("ESP32Client", mqttUser, mqttPassword )) {

      Serial.println("connected");  

    } else {

      Serial.print("failed with state ");
      Serial.println(client.state());
      delay(1000);

    }
  }

  client.subscribe("alex9ufo-DHT11-RaspiData");
  delay(200);
  client.subscribe("alex9ufo-temp-RaspiData");
  delay(200);
  client.subscribe("alex9ufo-humi-RaspiData");
  delay(200);

}

void loop() {
  client.loop();
}

NODEMCU (ESP32) Subscribing to MQTT topic




#include <ESP8266WiFi.h>
#include <PubSubClient.h>

//const char* ssid = "yourNetworkName";
//const char* password =  "yourNetworkPassword";
const char* ssid = "My ASUS";
const char* password =  "alex9981";
//const char* mqttServer = "m11.cloudmqtt.com";
const char* mqttserver = "broker.mqtt-dashboard.com";
const int mqttPort = 1883;
//const char* mqttUser = "yourMQTTuser";
//const char* mqttPassword = "yourMQTTpassword";
const char* mqttUser = "";
const char* mqttPassword = "";

WiFiClient espClient;
PubSubClient client(espClient);

void callback(char* topic, byte* payload, unsigned int length) {

  Serial.print("Message arrived in topic: ");
  Serial.println(topic);

  Serial.print("Message:");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }

  Serial.println();
  Serial.println("-----------------------");

}

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
  Serial.println("Connected to the WiFi network");

  client.setServer(mqttserver, mqttPort);
  client.setCallback(callback);


  while (!client.connected()) {
    Serial.println("Connecting to MQTT...");

    if (client.connect("ESP32Client", mqttUser, mqttPassword )) {

      Serial.println("connected"); 

    } else {

      Serial.print("failed with state ");
      Serial.println(client.state());
      delay(2000);

    }
  }

  client.subscribe("alex9ufo-DHT11-RaspiData");

}

void loop() {
  client.loop();
}

  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...