void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
int ledpin=8;
int buzzerPin = 9;
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(ledpin,OUTPUT);
pinMode (buzzerPin, OUTPUT);
}
void loop()
{
char receiveVal; // Defined receive data
receiveVal = Serial.read(); //Save the serial data received
if(receiveVal == '1') //Receive data is 1, lit LED lights
{
digitalWrite(ledpin,HIGH); //print out the value of the LED
Serial.println("led on"); //send data to the serial monitor
}
if(receiveVal == '0') //Receive data is 0, off LED lights
{
digitalWrite(ledpin,LOW); //print out the value of the LED
Serial.println("led off");//send data to the serial monitor
}
if(receiveVal == '2') //Receive data is 1, lit LED lights
{
digitalWrite (buzzerPin, HIGH);
Serial.println("buzzer:ON"); //send data to the serial monitor
}
if(receiveVal == '3') //Receive data is 0, off LED lights
{
digitalWrite (buzzerPin, LOW);
Serial.println("buzzer off");//send data to the serial monitor
}
delay(1000);
}
import serial
import time
from flask import Flask, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
app = Flask(__name__)
api = Api(app)
serialPort = serial.Serial(port = "COM7", baudrate=9600,
bytesize=8, timeout=2, stopbits=serial.STOPBITS_ONE)
serialString = "" # Used to hold data coming over UART
class Arduino(Resource):
def get(self, indicator):
#print("hello")
serialPort.write(bytes(indicator, 'UTF-8'))
while serialPort.inWaiting() > 0:
out = serialPort.read()
print(out)
class Home(Resource):
def get(self):
print("Hello")
api.add_resource(Arduino, '/Arduino/<indicator>')
api.add_resource(Home, '/')
if __name__ == '__main__':
app.run(port='5002')
<Label text="LED's Status" />
<Switch class="sapUiButtonEmphasizedBackground" state="false" change="onChangeLED">
<layoutData>
<FlexItemData growFactor="1" />
</layoutData>
</Switch>
<Label text="Buzzer" />
<Switch class="sapUiButtonEmphasizedBackground" state="false" change="onChangeBuzzer">
<layoutData>
<FlexItemData growFactor="1" />
</layoutData>
</Switch>
let url="<url>";
if ( evt.getParameters().state == true){
url = url + '/2';
} else {
url = url + '/3';
}
$.ajax({
type: "GET",
url: url ,
dataType: "json",
crossDomain: true,
success: function(result) {
MessageToast.show("Operation Successful!");
},
error: function(response) {
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
10 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |