Share

No Title

Public

13 February 2019

Views: 7

//includere biblioteci
#include "MeMCore.h"
#include "MeRGBLineFollower.h"
#include "Adafruit_NeoPixel.h"

//declarare motoare


//declarare senzori
MeRGBLineFollower RGBLineFollower(PORT_3);
MeUltrasonicSensor SenzorDistanta(PORT_2);
Adafruit_NeoPixel LEDs = Adafruit_NeoPixel(2, 13, NEO_GRB + NEO_KHZ800);

//declarare variabile
int distanta = 0;
int16_t turnoffset = 0;
int16_t set_speed = 100;
int16_t rgb1 = 0;
int16_t rgb2 = 0;
int16_t rgb3 = 0;
int16_t rgb4 = 0;


void setup()
{
Serial.begin(9600);//declarare consola seriala
//declarare RGBLineFollower
//declarare player audio
//setare volum audio player
//asteapta 0,1 secunde
AudioPlayer.stopMusic();
delay(100);
LEDs.begin();
}

void loop()
{
RGBLineFollower.loop();
distanta = SenzorDistanta.distanceCm();
turnoffset = RGBLineFollower.getPositionOffset();
rgb1 = RGBLineFollower.getADCValueRGB1();
rgb2 = RGBLineFollower.getADCValueRGB2();
rgb3 = RGBLineFollower.getADCValueRGB3();
rgb4 = RGBLineFollower.getADCValueRGB4();

if (rgb1 < 13 && rgb2 < 13 && rgb3 < 13 && rgb4 < 13) {
LEDs.setPixelColor(1, LEDs.Color(255, 0, 0)); //setare culoare LED1 (rosu)
LEDs.setPixelColor(0, LEDs.Color(255, 0, 0));
LEDs.show();
delay(300);
//oprire motoare pentru 3 secunde
//setare culoare LED1 (rosu)
delay(200);


}
else {
MotorStanga.run(-(set_speed + turnoffset));
MotorDreapta.run(set_speed - turnoffset);
}

if (rgb1 < 13 && rgb2 < 13 && rgb3 > 13 && rgb4 > 13 )
{
//oprire motoare
delay(500);

for (int i = 0; i < 5; i++)
{
//setare culoare LED1 (rosu)

delay(200);
//setare culoare LED1 (rosu)

delay(200);
}
MotorStanga.run(0);
MotorDreapta.run(0);
delay(200);
MotorStanga.run(0);
MotorDreapta.run(150);
delay(600);
}

if (rgb3 < 13 && rgb4 < 13 && rgb1 > 13 && rgb2 > 13 )
{
MotorStanga.run(0);
MotorDreapta.run(0);
delay(500);

for (int i = 0; i < 5; i++)
{
LEDs.setPixelColor(0, LEDs.Color(255, 255, 0)); //setare culoare LED1 (rosu)
LEDs.show();
delay(200);
LEDs.setPixelColor(0, LEDs.Color(0, 0, 0)); //setare culoare LED1 (rosu)
LEDs.show();
delay(200);
}
MotorStanga.run(0);
MotorDreapta.run(0);
delay(200);
MotorStanga.run(-150);
MotorDreapta.run(0);
delay(600);
}
}

Advertisement

Disable Third Party Ads