How to merge three scetches?
hello guys! have several working scetches want merge one. first 1 turns on led when sound detected, second 1 turns on led when light detected , third 1 turns on led when gas detected. can me how merge them?
// set pin numbers:
const int soundpin = 2; // number of sound sensor pin
const int ledpin = 13; // number of led pin
// variables change:
int soundstate = 0; // variable reading sound sensor status
void setup() {
// initialize led pin output:
pinmode(ledpin, output);
// initialize sound sensor pin input:
pinmode(soundpin, input);
}
void loop(){
// read state of sound sensor value:
soundstate = digitalread(soundpin);
// check if sound detected.
// if is, sound sensor :pw:
if (soundstate == low) {
// turn led on:
digitalwrite(ledpin, high);
delay(60000);
//wait 60 seconds , turn off
digitalwrite(ledpin, low);
}
else {
// turn led off:
digitalwrite(ledpin, low);
}
}
const int lightpin = 2;
const int ledpin = 13;
int value = 0;
void setup() {
pinmode(ledpin, output);
pinmode(lightpin, input);
serial.begin(9600);
}
void loop() {
value = digitalread(lightpin);
if (value == high) {
// turn led on:
digitalwrite(ledpin, high);
delay(60000);
//wait 60 seconds , turn off
digitalwrite(ledpin, low);
}
else {
// turn led off:
digitalwrite(ledpin, low);
}
}
// these constants won't change. they're used give names
// pins used:
const int analoginpin = a0; // analog input pin potentiometer attached to
const int ledpin = 13; // led connected digital pin 13
int sensorvalue = 0; // value read sensor
void setup() {
// initialize serial communications @ 9600 bps:
serial.begin(9600);
pinmode(ledpin, output); // sets digital pin output
}
void loop() {
// read analog in value:
sensorvalue = analogread(analoginpin);
// determine alarm status
if (sensorvalue >= 200)
{
digitalwrite(ledpin, high); // sets led on
}
else
{
digitalwrite(ledpin, low); // sets led off
}
// print results serial monitor:
serial.print("sensor = " );
serial.println(sensorvalue);
// wait 100 milliseconds before next loop
// analog-to-digital converter settle
// after last reading:
delay(100);
}
// set pin numbers:
const int soundpin = 2; // number of sound sensor pin
const int ledpin = 13; // number of led pin
// variables change:
int soundstate = 0; // variable reading sound sensor status
void setup() {
// initialize led pin output:
pinmode(ledpin, output);
// initialize sound sensor pin input:
pinmode(soundpin, input);
}
void loop(){
// read state of sound sensor value:
soundstate = digitalread(soundpin);
// check if sound detected.
// if is, sound sensor :pw:
if (soundstate == low) {
// turn led on:
digitalwrite(ledpin, high);
delay(60000);
//wait 60 seconds , turn off
digitalwrite(ledpin, low);
}
else {
// turn led off:
digitalwrite(ledpin, low);
}
}
const int lightpin = 2;
const int ledpin = 13;
int value = 0;
void setup() {
pinmode(ledpin, output);
pinmode(lightpin, input);
serial.begin(9600);
}
void loop() {
value = digitalread(lightpin);
if (value == high) {
// turn led on:
digitalwrite(ledpin, high);
delay(60000);
//wait 60 seconds , turn off
digitalwrite(ledpin, low);
}
else {
// turn led off:
digitalwrite(ledpin, low);
}
}
// these constants won't change. they're used give names
// pins used:
const int analoginpin = a0; // analog input pin potentiometer attached to
const int ledpin = 13; // led connected digital pin 13
int sensorvalue = 0; // value read sensor
void setup() {
// initialize serial communications @ 9600 bps:
serial.begin(9600);
pinmode(ledpin, output); // sets digital pin output
}
void loop() {
// read analog in value:
sensorvalue = analogread(analoginpin);
// determine alarm status
if (sensorvalue >= 200)
{
digitalwrite(ledpin, high); // sets led on
}
else
{
digitalwrite(ledpin, low); // sets led off
}
// print results serial monitor:
serial.print("sensor = " );
serial.println(sensorvalue);
// wait 100 milliseconds before next loop
// analog-to-digital converter settle
// after last reading:
delay(100);
}
you start 1 of sketches ,
1) merge global variables,
2) merge functions
3) merge includes
4) merge setup() code
5) merge loop code()
in every merge step should resolve conflicting names, #parameters etc.
do every additional sketch.
so step 1 lead - note there conflicts resolve!
1) merge global variables,
2) merge functions
3) merge includes
4) merge setup() code
5) merge loop code()
in every merge step should resolve conflicting names, #parameters etc.
do every additional sketch.
so step 1 lead - note there conflicts resolve!
code: [select]
// set pin numbers:
const int soundpin = 2; // number of sound sensor pin
const int ledpin = 13; // number of led pin
// these constants won't change. they're used give names
// pins used:
const int analoginpin = a0; // analog input pin potentiometer attached to
const int ledpin = 13; // led connected digital pin 13
const int lightpin = 2;
const int ledpin = 13;
int value = 0;
int sensorvalue = 0; // value read sensor
// variables change:
int soundstate = 0; // variable reading sound sensor status
void setup() {
// initialize led pin output:
pinmode(ledpin, output);
// initialize sound sensor pin input:
pinmode(soundpin, input);
}
void loop(){
// read state of sound sensor value:
soundstate = digitalread(soundpin);
// check if sound detected.
// if is, sound sensor :pw:
if (soundstate == low) {
// turn led on:
digitalwrite(ledpin, high);
delay(60000);
//wait 60 seconds , turn off
digitalwrite(ledpin, low);
}
else {
// turn led off:
digitalwrite(ledpin, low);
}
}
Arduino Forum > Using Arduino > Programming Questions > How to merge three scetches?
arduino
Comments
Post a Comment