/* Led.ino * * COM * ledPin * */ // () #define ledpin 8 // "" String inString = ""; void setup() { Serial.begin(9600); pinMode(ledpin, OUTPUT); digitalWrite(ledpin, LOW); } void loop() { // COM while (Serial.available() > 0) { int inChar = Serial.read(); if (isDigit(inChar)) { // 1 , // inString += (char)inChar; } // if (inChar == '\n') { // digitalWrite(ledpin, HIGH); int time = inString.toInt(); delay(time); digitalWrite(ledpin, LOW); // inString = ""; } } }
/// 1000\n ClassMethod SendSerial() { set port = "COM1" open port:(:::" 0801n0":/BAUD=9600) // set old = $IO // - use port // com write $Char(10) // hang 1 write 1000 _ $Char(10) // 1000\n use old // close port // }
do ##class(Arduino.Habr).SendSerial()
/* Keypadtest.ino * * Keypad * Keypad Arduino * rowPins[] and colPins[]. * */ // : // https://github.com/Chris--A/Keypad #include <Keypad.h> const byte ROWS = 4; // const byte COLS = 4; // // char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; // keypad 1-8 (-) Arduino 11-4. 1->11, 2->10, ... , 8->4 // keypad ROW0, ROW1, ROW2 ROW3 Arduino byte rowPins[ROWS] = { 7, 6, 5, 4 }; // keypad COL0, COL1 and COL2 Arduino byte colPins[COLS] = { 8, 9, 10, 11 }; // Keypad Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); #define ledpin 13 void setup() { Serial.begin(9600); } void loop() { char key = kpd.getKey(); // if(key) { switch (key) { case '#': Serial.println(); default: Serial.print(key); } } }
/// ( ) ClassMethod ReceiveOneLine() As %String { port = "COM1" set str="" try { open port:(:::" 0801n0":/BAUD=9600) set old = $io // - use port read str // , use old close port } catch ex { close port } return str }
write ##class(Arduino.Habr).ReceiveOneLine()
/* Meteo.ino * * , , * COM port * : H=1.0;T=1.0;LL=1; */ // () int lightPin = 0; // DHT-11 () int DHpin = 8; // , DHT-11 byte dat[5]; // void setup() { Serial.begin(9600); pinMode(DHpin,OUTPUT); } /* * setup() * */ void loop() { delay(1000); // 1 int lightLevel = analogRead(lightPin); // temp_hum(); // dat // Serial.print("H="); Serial.print(dat[0], DEC); Serial.print('.'); Serial.print(dat[1],DEC); Serial.print(";T="); Serial.print(dat[2], DEC); Serial.print('.'); Serial.print(dat[3],DEC); Serial.print(";LL="); Serial.print(lightLevel); Serial.println(";"); } // DHT-11 dat void temp_hum() { digitalWrite(DHpin,LOW); delay(30); digitalWrite(DHpin,HIGH); delayMicroseconds(40); pinMode(DHpin,INPUT); while(digitalRead(DHpin) == HIGH); delayMicroseconds(80); if(digitalRead(DHpin) == LOW); delayMicroseconds(80); for(int i=0;i<4;i++) { dat[i] = read_data(); } pinMode(DHpin,OUTPUT); digitalWrite(DHpin,HIGH); } // DHT-11 byte read_data() { byte data; for(int i=0; i<8; i++) { if(digitalRead(DHpin) == LOW) { while(digitalRead(DHpin) == LOW); delayMicroseconds(30); if(digitalRead(DHpin) == HIGH) { data |= (1<<(7-i)); } while(digitalRead(DHpin) == HIGH); } } return data; }
H = 34.0; T = 24.0; LL = 605;
Class Arduino.Info Extends %Persistent { Parameter SerialPort As %String = "com1"; Property DateTime As %DateTime; Property Temperature As %Double; Property Humidity As %Double(MAXVAL = 100, MINVAL = 0); Property Brightness As %Double(MAXVAL = 100, MINVAL = 0); Property Volume As %Double(MAXVAL = 100, MINVAL = 0); ClassMethod AddNew(Temperature = 0, Humidity = 0, Brightness = 0, Volume = 0) { set obj = ..%New() set obj.DateTime=$ZDT($H,3,1) set obj.Temperature=Temperature set obj.Humidity=Humidity set obj.Brightness=Brightness/1023*100 set obj.Volume=Volume write $SYSTEM.Status.DisplayError(obj.%Save()) }
/// H=34.0;T=24.0;LL=605;\n /// Arduino.Info ClassMethod ReceiveSerial(port = {..#SerialPort}) { try { open port:(:::" 0801n0":/BAUD=9600) set old = $IO use port for { read x // set Humidity = $Piece($Piece(x,";",1),"=",2) set Temperature = $Piece($Piece(x,";",2),"=",2) set Brightness = $Piece($Piece(x,";",3),"=",2) if (x '= "") { do ..AddNew(Temperature,Humidity,Brightness) // } } } catch anyError { close port } }
write ##class(Arduino.Info).ReceiveSerial()
Source: https://habr.com/ru/post/273749/
All Articles