#include Servo.h
Servo myservo; // create servo object to control a servo
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600); // 9600 baudrate of the HC-05 Bluetooth module
pinMode(8, OUTPUT);
myservo.attach(3);
}
void openFlower(){
myservo.write(40);
delay(15);
}
void closeFlower(){
myservo.write(110);
delay(15);
}
// the loop function runs over and over again forever
void loop() {
while(Serial.available()) {
int command = Serial.read();
Serial.print(command);
if (command == 49){
openFlower();
}
else {
if(command == 48) {
closeFlower();
}
}
delay(15);
}
}
import processing.serial.*;
import processing.dxf.*;
boolean toggle = true;
PImage logo1;
PImage logo2;
int width = 800;
int height = 600;
Serial myPort;
int portNumber;
void setup() {
size(800, 600, P3D);
smooth();
background(255);
logo1 = loadImage("Logo1.jpg");
logo1.resize(width, height);
logo2 = loadImage("Logo2.jpg");
logo2.resize(width, height);
image(logo1, 0, 0);
for (int i=0; i< Serial.list().length; i++) {
if (Serial.list()[i].length() > 17) {
if(Serial.list()[i].substring(0,18).equals("/dev/cu.HC-05-DevB")) {
portNumber = i;
}
}
}
println(Serial.list());
String portName = Serial.list()[portNumber];
myPort = new Serial(this, portName, 9600);
myPort.write("0");
}
void draw() {
}
void mousePressed() {
blendMode(REPLACE);
background(0);
blendMode(ADD);
if (toggle) {
myPort.write("0");
image(logo1, 0, 0);
} else {
myPort.write("1");
image(logo2, 0, 0);
}
toggle = !toggle;
}
#include SoftwareSerial.h
const int rx=0;
const int tx=1;
SoftwareSerial mySerial(rx,tx);
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(rx, INPUT);
pinMode(tx, OUTPUT);
mySerial.begin(9600); // 9600 baudrate of the HC-05 Bluetooth module
pinMode(8, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
while(mySerial.available()) {
int command = mySerial.read();
//mySerial.print(command);
if (command == 49){
digitalWrite(8, HIGH);
}
else {
if(command == 48) {
digitalWrite(8, LOW);
}
}
delay(15);
}
}