Skip to content

Instantly share code, notes, and snippets.

@shaon1
Created April 30, 2017 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaon1/3e469ddf8a16c71f6e7ca16d24d28e92 to your computer and use it in GitHub Desktop.
Save shaon1/3e469ddf8a16c71f6e7ca16d24d28e92 to your computer and use it in GitHub Desktop.
Total code
#include <SoftwareSerial.h>
#include<Servo.h>
SoftwareSerial BT(10,11); //(tx,rx);
Servo servoTrans;
int i=0,x=0;
String str;
void setup() {
BT.begin(9600);
pinMode(8,OUTPUT);
pinMode(5,OUTPUT);
servoTrans.attach(3);
servoTrans.write(0);
Serial.begin(9600);
}
void loop() {
while(BT.available())
{
delay(10);
char c=BT.read();
str += c;
}
if (str=="led on")
{
digitalWrite(8,HIGH);
}
else if(str=="led off")
{
digitalWrite(8,LOW);
}
/*if(str=="180")
{
servoTrans.write(180);
delay (4) ;
}
if(str=="0")
{
servoTrans.write(0);
delay (4) ;
}
*/
if(str.toInt()>0)
{
x=str.toInt();
servoTrans.write(x);
}
str="";
if(digitalRead(8)==HIGH)
{
delay(500);
digitalWrite(5, HIGH);
}
else if(digitalRead(8)==LOW)
{
delay(500);
digitalWrite(5, LOW);
}
if(servoTrans.read()<=45)
{
/*Send data*/
}
}
#include <VirtualWire.h> //Load the library
int mapped; //Define the temp float variable
int sensor = 0; // sensor middle pin on analog pin 0
char msg[6];
int x, y;
void setup()
{
Serial.begin(9600);
vw_set_tx_pin(9); // Sets pin D12 as the TX pin
vw_setup(2000); // Bits per sec
pinMode(6,INPUT);
pinMode(5,OUTPUT);
}
void loop()
{
/*if (digitalRead(6) == HIGH)
{
delay(500);
digitalWrite(5,HIGH);
}
else if(digitalRead(6)==LOW)
{
delay(500);
}
*/
x=100;
y=200;
if (digitalRead(6) == HIGH) {
mapped = y;
Serial.println(mapped);
dtostrf(mapped, 6, 2, msg); //converts the float into a char
vw_send((uint8_t *)msg, strlen(msg)); //transmits the data
vw_wait_tx(); // Wait until the whole message is gone
delay(50);
}
else if(digitalRead(6) == LOW){
mapped = 300;
Serial.println(mapped);
dtostrf(mapped, 6, 2, msg); //converts the float into a char
vw_send((uint8_t *)msg, strlen(msg)); //transmits the data
vw_wait_tx(); // Wait until the whole message is gone
delay(50);
}
}
#include <VirtualWire.h> //Load the library
int mapped; //Define the temp float variable
int sensor = 0; // sensor middle pin on analog pin 0
char msg[6];
int x, y;
void setup()
{
Serial.begin(9600);
vw_set_tx_pin(9); // Sets pin D12 as the TX pin
vw_setup(2000); // Bits per sec
pinMode(6,INPUT);
pinMode(5,OUTPUT);
}
void loop()
{
/*if (digitalRead(6) == HIGH)
{
delay(500);
digitalWrite(5,HIGH);
}
else if(digitalRead(6)==LOW)
{
delay(500);
}
*/
x=100;
y=200;
if (digitalRead(6) == HIGH) {
mapped = y;
Serial.println(mapped);
dtostrf(mapped, 6, 2, msg); //converts the float into a char
vw_send((uint8_t *)msg, strlen(msg)); //transmits the data
vw_wait_tx(); // Wait until the whole message is gone
delay(50);
}
else if(digitalRead(6) == LOW){
mapped = 300;
Serial.println(mapped);
dtostrf(mapped, 6, 2, msg); //converts the float into a char
vw_send((uint8_t *)msg, strlen(msg)); //transmits the data
vw_wait_tx(); // Wait until the whole message is gone
delay(50);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment