จะทำจาก 3D printer แล้วให้มีกลไกเคลื่อนไหวได้
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
#include <WiFi.h>
const char* ssid = "yourssid";
const char* password = "yourpasswd";
IPAddress local_IP(192, 168, 1, 100);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
pinMode(2, OUTPUT); // set the LED pin mode
digitalWrite(2, HIGH);
delay(10);
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
WiFi.begin(ssid, password);
server.begin();
}
int value = 0;
void loop(){
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("Click <a href=\"/H\">here</a> to turn the LED on pin 2 on.<br>");
client.print("Click <a href=\"/L\">here</a> to turn the LED on pin 2 off.<br>");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(2, LOW[img][/img]); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L")) {
digitalWrite(2, HIGH; // GET /L turns the LED off
}
}
}
// close the connection:
client.stop();
Serial.println("Client Disconnected.");
}
}
Quote- ระบบ thermal fuse ตัดไฟอัตโนมัติ เมื่อมอเตอร์มีอุณหภูมิสูงผิดปกติ
- ขนาดใบพัด (นิ้ว) 18
- แรงดันไฟ (โวลท์) 220
- ความถี่ (เฮิร์ต) 50
- กำลังไฟฟ้า (วัตต์) 126
- กระแสไฟฟ้า (แอมป์) 0.72
- วัสดุฉนวนชนิด E
- ค่าประสิทธิภาพการระบายลม
- (m3/min/w) 1.27
- ระดับแรงลม 3
- สวิตซ์ควบคุมแรงลม หมุนปรับ
String inputString = "";
boolean stringComplete = false;
void setup()
{
Serial.begin(9600);
inputString.reserve(200);
for(int i=2 ;i<19;i++)
{
pinMode(i,OUTPUT);
}
}
void loop()
{
if (stringComplete)
{
int pin = stringToNumber(inputString);
for(int i=2; i<19; i++)
{
if(pin == i*10)digitalWrite(i,LOW);
if(pin == (i*10)+1)digitalWrite(i,HIGH);
}
inputString = "";
stringComplete = false;
}
}
int stringToNumber(String thisString) {
int i, value = 0, length;
length = thisString.length();
for(i=0; i<length; i++) {
value = (10*value) + thisString.charAt(i)-(int) '0';;
}
return value;
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
if (inChar == ' ')
{
stringComplete = true;
}
else
{
inputString += inChar;
}
}
}
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void)
{
Serial.begin(9600);
sensors.begin();
}
void loop(void)
{
sensors.requestTemperatures();
Serial.println(sensors.getTempCByIndex(0));
}
public partial class Form1 : Form
{
string RxString;
uint rxCounter;
public Form1()
{
InitializeComponent();
}
private void buttonStart_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM3";
serialPort1.BaudRate = 9600;
try { serialPort1.Open(); }
catch (Exception ex) { MessageBox.Show(ex.Message); }
if (serialPort1.IsOpen)
{
buttonStart.Enabled = false;
buttonStop.Enabled = true;
textBox1.ReadOnly = false;
}
}
private void buttonStop_Click(object sender, EventArgs e)
{
try
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
buttonStart.Enabled = true;
buttonStop.Enabled = false;
textBox1.ReadOnly = true;
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (serialPort1.IsOpen) serialPort1.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.Text = RxString;
chart1.ChartAreas[0].AxisY.Minimum = 25;
chart1.ChartAreas[0].AxisY.Maximum = 37;
chart1.ChartAreas[0].AxisY.Interval = 1;
chart1.ChartAreas[0].AxisX.Interval = 60;
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisY.Title = "C";
chart1.ChartAreas[0].AxisX.Title = "Time";
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;
chart1.Series[0].Color = Color.Red;
chart1.Series[0].Points.AddXY(rxCounter, RxString);
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
RxString = serialPort1.ReadLine();
this.Invoke(new EventHandler(DisplayText));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.Util;
namespace Color_detection
{
public partial class Form1 : Form
{
#region Globle Var
private Capture capture;
private bool captureInProgress;
private bool imageInProgress;
String filenameload;
Image<Bgr, Byte> ImageFrame = new Image<Bgr, Byte>(320, 240);
Image<Bgr, Byte> ImageHSVwheel = new Image<Bgr, Byte>("HSV-Wheel.png");
Image<Hsv, Byte> hsvImage = new Image<Hsv, Byte>(0, 0);
int diff_LH;
#endregion
public Form1()
{
InitializeComponent();
imageBox3.Image = ImageHSVwheel;
Application.Idle += ProcessFrame;
}
#region Main Program
private void ProcessFrame(object sender, EventArgs e)
{
if (captureInProgress)
{
ImageFrame = capture.QueryFrame();
ImageFrame = ImageFrame.Resize(imageBox1.Width, imageBox1.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
imageBox1.Image = ImageFrame;
ImageProcessing();
}
if (imageInProgress)
{
ImageFrame = new Image<Bgr, byte>(filenameload);
int[] whD = scaleImage(ImageFrame.Width, ImageFrame.Height);
ImageFrame = ImageFrame.Resize(whD[0], whD[1], Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
imageBox1.Image = ImageFrame;
ImageProcessing();
}
}
private void ImageProcessing()
{
Image<Gray, Byte> ImageFrameDetection = cvAndHsvImage(
ImageFrame,
Convert.ToInt32(numeric_HL.Value), Convert.ToInt32(numeric_HH.Value),
Convert.ToInt32(numeric_SL.Value), Convert.ToInt32(numeric_SH.Value),
Convert.ToInt32(numeric_VL.Value), Convert.ToInt32(numeric_VH.Value),
checkBox_EH.Checked, checkBox_ES.Checked, checkBox_EV.Checked, checkBox_IV.Checked);
if (iB2C == 0) imageBox2.Image = ImageFrameDetection;
if (iB2C == 1)
{
Image<Bgr, Byte> imgF = new Image<Bgr, Byte>(ImageFrame.Width, ImageFrame.Height);
Image<Bgr, Byte> imgD = ImageFrameDetection.Convert<Bgr, Byte>();
CvInvoke.cvAnd(ImageFrame, imgD, imgF, IntPtr.Zero);
imageBox2.Image = imgF;
}
if (iB2C == 2)
{
Image<Bgr, Byte> imgF = new Image<Bgr, Byte>(ImageFrame.Width, ImageFrame.Height);
Image<Bgr, Byte> imgD = ImageFrameDetection.Convert<Bgr, Byte>();
CvInvoke.cvAnd(ImageFrame, imgD, imgF, IntPtr.Zero);
for (int x = 0; x < imgF.Width; x++)
for (int y = 0; y < imgF.Height; y++)
{
{
Bgr c = imgF[y, x];
if (c.Red == 0 && c.Blue == 0 && c.Green == 0)
{
imgF[y, x] = new Bgr(255, 255, 255);
}
}
}
imageBox2.Image = imgF;
}
if (checkBox_VAr.Checked) RecDetection(ImageFrameDetection, ImageFrame, trackBar_VAr.Value);
Image<Gray, Byte> ImageHSVwheelDetection = cvAndHsvImage(
ImageHSVwheel,
Convert.ToInt32(numeric_HL.Value), Convert.ToInt32(numeric_HH.Value),
Convert.ToInt32(numeric_SL.Value), Convert.ToInt32(numeric_SH.Value),
Convert.ToInt32(numeric_VL.Value), Convert.ToInt32(numeric_VH.Value),
checkBox_EH.Checked, checkBox_ES.Checked, checkBox_EV.Checked, checkBox_IV.Checked);
imageBox4.Image = ImageHSVwheelDetection;
}
#endregion
#region Image Processing
private void RecDetection(Image<Gray, Byte> img, Image<Bgr, Byte> showRecOnImg, int areaV)
{
Image<Gray, Byte> imgForContour = new Image<Gray, byte>(img.Width, img.Height);
CvInvoke.cvCopy(img, imgForContour, System.IntPtr.Zero);
IntPtr storage = CvInvoke.cvCreateMemStorage(0);
IntPtr contour = new IntPtr();
CvInvoke.cvFindContours(
imgForContour,
storage,
ref contour,
System.Runtime.InteropServices.Marshal.SizeOf(typeof(MCvContour)),
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL,
Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE,
new Point(0, 0));
Seq<Point> seq = new Seq<Point>(contour, null);
for (; seq != null && seq.Ptr.ToInt64() != 0; seq = seq.HNext)
{
Rectangle bndRec = CvInvoke.cvBoundingRect(seq, 2);
double areaC = CvInvoke.cvContourArea(seq, MCvSlice.WholeSeq, 1) * -1;
if (areaC > areaV)
{
CvInvoke.cvRectangle(showRecOnImg, new Point(bndRec.X, bndRec.Y),
new Point(bndRec.X + bndRec.Width, bndRec.Y + bndRec.Height),
new MCvScalar(0, 0, 255), 2, LINE_TYPE.CV_AA, 0);
}
}
}
private Image<Gray, Byte> cvAndHsvImage(Image<Bgr, Byte> imgFame, int L1, int H1, int L2, int H2, int L3, int H3, bool H, bool S, bool V, bool I)
{
Image<Hsv, Byte> hsvImage = imgFame.Convert<Hsv, Byte>();
Image<Gray, Byte> ResultImage = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
Image<Gray, Byte> ResultImageH = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
Image<Gray, Byte> ResultImageS = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
Image<Gray, Byte> ResultImageV = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
Image<Gray, Byte> img1 = inRangeImage(hsvImage, L1, H1, 0);
Image<Gray, Byte> img2 = inRangeImage(hsvImage, L2, H2, 1);
Image<Gray, Byte> img3 = inRangeImage(hsvImage, L3, H3, 2);
Image<Gray, Byte> img4 = inRangeImage(hsvImage, 0, L1, 0);
Image<Gray, Byte> img5 = inRangeImage(hsvImage, H1, 180, 0);
#region checkBox Color Mode
if (H)
{
if (I)
{
CvInvoke.cvOr(img4, img5, img4, System.IntPtr.Zero);
ResultImageH = img4;
}
else { ResultImageH = img1; }
}
if (S) ResultImageS = img2;
if (V) ResultImageV = img3;
if (H && !S && !V) ResultImage = ResultImageH;
if (!H && S && !V) ResultImage = ResultImageS;
if (!H && !S && V) ResultImage = ResultImageV;
if (H && S && !V)
{
CvInvoke.cvAnd(ResultImageH, ResultImageS, ResultImageH, System.IntPtr.Zero);
ResultImage = ResultImageH;
}
if (H && !S && V)
{
CvInvoke.cvAnd(ResultImageH, ResultImageV, ResultImageH, System.IntPtr.Zero);
ResultImage = ResultImageH;
}
if (!H && S && V)
{
CvInvoke.cvAnd(ResultImageS, ResultImageV, ResultImageS, System.IntPtr.Zero);
ResultImage = ResultImageS;
}
if (H && S && V)
{
CvInvoke.cvAnd(ResultImageH, ResultImageS, ResultImageH, System.IntPtr.Zero);
CvInvoke.cvAnd(ResultImageH, ResultImageV, ResultImageH, System.IntPtr.Zero);
ResultImage = ResultImageH;
}
#endregion
CvInvoke.cvErode(ResultImage, ResultImage, (IntPtr)null, 1);
return ResultImage;
}
private Image<Gray, Byte> inRangeImage(Image<Hsv, Byte> hsvImage, int Lo, int Hi, int con)
{
Image<Gray, Byte> ResultImage = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height);
Image<Gray, Byte> IlowCh = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height, new Gray(Lo));
Image<Gray, Byte> IHiCh = new Image<Gray, Byte>(hsvImage.Width, hsvImage.Height, new Gray(Hi));
CvInvoke.cvInRange(hsvImage[con], IlowCh, IHiCh, ResultImage);
return ResultImage;
}
private int[] scaleImage(int wP, int hP)
{
int[] dR = new int[2];
int ra;
if (wP != 0)
{
ra = (100 * 320) / wP;
wP = 320;
hP = (hP * ra) / 100;
if (hP != 0 && hP > 240)
{
ra = (100 * 240) / hP;
hP = 240;
wP = (wP * ra) / 100;
}
dR[0] = wP;
dR[1] = hP;
}
return dR;
}
#endregion
#region // Tooth Even
private void numeric_Lo_ValueChanged(object sender, EventArgs e)
{
trackBar_HL.Value = Convert.ToInt32(numeric_HL.Value);
trackBar_SL.Value = Convert.ToInt32(numeric_SL.Value);
trackBar_VL.Value = Convert.ToInt32(numeric_VL.Value);
}
private void numeric_Hi_ValueChanged(object sender, EventArgs e)
{
trackBar_HH.Value = Convert.ToInt32(numeric_HH.Value);
trackBar_SH.Value = Convert.ToInt32(numeric_SH.Value);
trackBar_VH.Value = Convert.ToInt32(numeric_VH.Value);
}
private void numeric_VAr_ValueChanged(object sender, EventArgs e)
{
trackBar_VAr.Value = Convert.ToInt32(numeric_VAr.Value);
}
private void trackBar_Lo_ValueChanged(object sender, EventArgs e)
{
if (trackBar_HL.Value >= trackBar_HH.Value && !checkBox_LH.Checked)
trackBar_HH.Value = trackBar_HL.Value;
if (checkBox_LH.Checked && trackBar_HL.Value + diff_LH <= 180)
trackBar_HH.Value = trackBar_HL.Value + diff_LH;
numeric_HL.Value = trackBar_HL.Value;
numeric_SL.Value = trackBar_SL.Value;
numeric_VL.Value = trackBar_VL.Value;
}
private void trackBar_Hi_ValueChanged(object sender, EventArgs e)
{
if (trackBar_HH.Value <= trackBar_HL.Value && !checkBox_LH.Checked)
trackBar_HL.Value = trackBar_HH.Value;
if (checkBox_LH.Checked && trackBar_HH.Value - diff_LH >= 0)
trackBar_HL.Value = trackBar_HH.Value - diff_LH;
numeric_HH.Value = trackBar_HH.Value;
numeric_SH.Value = trackBar_SH.Value;
numeric_VH.Value = trackBar_VH.Value;
}
private void trackBar_VAr_ValueChanged(object sender, EventArgs e)
{
numeric_VAr.Value = trackBar_VAr.Value;
}
private void checkBox_LH_CheckedChanged(object sender, EventArgs e)
{
diff_LH = trackBar_HH.Value - trackBar_HL.Value;
}
private void button1_Click(object sender, EventArgs e)
{
imageInProgress = false;
if (capture == null)
{
try
{
capture = new Capture();
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
if (capture != null)
{
if (captureInProgress)
{
captureInProgress = false;
}
else
{
captureInProgress = true;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
captureInProgress = false;
OpenFileDialog OpenFile = new OpenFileDialog();
if (OpenFile.ShowDialog() == DialogResult.OK)
{
filenameload = OpenFile.FileName;
imageInProgress = true;
}
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button5_Click(object sender, EventArgs e)
{
trackBar_HH.Value = 0;
trackBar_HL.Value = 0;
trackBar_SH.Value = 255;
trackBar_SL.Value = 0;
trackBar_VH.Value = 255;
trackBar_VL.Value = 0;
checkBox_LH.Checked = false;
checkBox_IV.Checked = false;
}
bool ib3C;
int ib3C_HV, ib3C_Lable_X, ib3C_Lable_Y;
private void imageBox3_MouseClick(object sender, MouseEventArgs e)
{
Image<Hsv, Byte> imgHsv = ImageHSVwheel.Convert<Hsv, Byte>();
Hsv hsv = imgHsv[e.Y, e.X];
if (!ib3C)
{
ib3C_HV = Convert.ToInt32(hsv.Hue);
ib3C_Lable_X = imageBox3.Location.X + e.X;
ib3C_Lable_Y = imageBox3.Location.Y + e.Y;
label_L.Location = new Point(ib3C_Lable_X, ib3C_Lable_Y);
label_H.Hide();
}
if (ib3C)
{
label_H.Show();
if (ib3C_HV < hsv.Hue)
{
trackBar_HL.Value = ib3C_HV;
trackBar_HH.Value = Convert.ToInt32(hsv.Hue);
label_H.Location = new Point(imageBox3.Location.X + e.X, imageBox3.Location.Y + e.Y);
}
else
{
trackBar_HH.Value = ib3C_HV;
trackBar_HL.Value = Convert.ToInt32(hsv.Hue);
ib3C_HV = 0;
label_H.Location = new Point(ib3C_Lable_X, ib3C_Lable_Y);
label_L.Location = new Point(imageBox3.Location.X + e.X, imageBox3.Location.Y + e.Y);
}
}
ib3C = !ib3C;
}
int iB2C;
private void imageBox2_Click(object sender, EventArgs e)
{
iB2C++;
if (iB2C > 2) iB2C = 0;
}
#endregion
}
}