diff --git a/example/FindAFriend/FindAFriend/.theia/launch.json b/example/FindAFriend/FindAFriend/.theia/launch.json new file mode 100644 index 0000000..7e4253b --- /dev/null +++ b/example/FindAFriend/FindAFriend/.theia/launch.json @@ -0,0 +1,8 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + "version": "0.2.0", + "configurations": [ + + ] +} diff --git a/example/FindAFriend/FindAFriend/FindAFriend.ino b/example/FindAFriend/FindAFriend/FindAFriend.ino new file mode 100644 index 0000000..54bd000 --- /dev/null +++ b/example/FindAFriend/FindAFriend/FindAFriend.ino @@ -0,0 +1,48 @@ +#include "Dezibot.h" + +Dezibot dezibot = Dezibot(); +const int centeredThreshold = 100; + +void setup() { + // put your setup code here, to run once: + dezibot.begin(); + Serial.begin(115200); +} + +void loop() { + int32_t leftValue = (int32_t)dezibot.lightDetection.getAverageValue(IR_LEFT, 20, 1); + int32_t rightValue = (int32_t)dezibot.lightDetection.getAverageValue(IR_RIGHT, 20, 1); + switch(dezibot.lightDetection.getBrightest(IR)){ + case IR_FRONT: + //correct Stearing to be centered + if( abs(leftValue-rightValue) + < centeredThreshold){ + dezibot.motion.move(1); + }else{ + if (leftValue > rightValue){ + dezibot.motion.rotateAnticlockwise(1); + } else{ + dezibot.motion.rotateClockwise(1); + } + } + dezibot.multiColorLight.setTopLeds(BLUE); + break; + case IR_LEFT: + dezibot.motion.rotateAnticlockwise(1); + dezibot.multiColorLight.setTopLeds(RED); + break; + case IR_RIGHT: + dezibot.motion.rotateClockwise(1); + dezibot.multiColorLight.setTopLeds(GREEN); + break; + case IR_BACK: + if(leftValue > rightValue){ + dezibot.motion.rotateAnticlockwise(1); + } else { + dezibot.motion.rotateClockwise(1); + } + dezibot.multiColorLight.setTopLeds(YELLOW); + break; + } + //delay(100); +} diff --git a/example/IRDirection/IRDirection/IRDirection.ino b/example/IRDirection/IRDirection/IRDirection.ino new file mode 100644 index 0000000..024edfd --- /dev/null +++ b/example/IRDirection/IRDirection/IRDirection.ino @@ -0,0 +1,35 @@ +#include "Dezibot.h" + +Dezibot dezibot = Dezibot(); +void setup() { + // put your setup code here, to run once: + dezibot.begin(); + Serial.begin(115200); +} + +void loop() { + // put your main code here, to run repeatedly: + Serial.print("Front:"); + Serial.print(dezibot.lightDetection.getAverageValue(IR_FRONT,20,1)); + Serial.print(",Left:"); + Serial.print(dezibot.lightDetection.getAverageValue(IR_LEFT,20,1)); + Serial.print(",Right:"); + Serial.print(dezibot.lightDetection.getAverageValue(IR_RIGHT,20,1)); + Serial.print(",Back:"); + Serial.println(dezibot.lightDetection.getAverageValue(IR_BACK,20,1)); + switch(dezibot.lightDetection.getBrightest(IR)){ + case IR_FRONT: + dezibot.multiColorLight.setTopLeds(BLUE); + break; + case IR_LEFT: + dezibot.multiColorLight.setTopLeds(RED); + break; + case IR_RIGHT: + dezibot.multiColorLight.setTopLeds(GREEN); + break; + case IR_BACK: + dezibot.multiColorLight.setTopLeds(YELLOW); + break; + } + //delay(100); +} diff --git a/example/example.ino b/example/example.ino index f055251..f0f619a 100644 --- a/example/example.ino +++ b/example/example.ino @@ -13,6 +13,6 @@ dezibot.multiColorLight.setLed(TOP_RIGHT,dezibot.multiColorLight.color(0,100,0)) dezibot.multiColorLight.blink(10,0x00FF0000,BOTTOM,500); delay(1000); -dezibot.multiColorLight.turnOff(ALL); +dezibot.multiColorLight.turnOffLed(ALL); delay(1000); } diff --git a/example/motion.ino b/example/motion.ino index e1f6d37..e14f760 100644 --- a/example/motion.ino +++ b/example/motion.ino @@ -2,7 +2,7 @@ Dezibot dezibot = Dezibot(); void setup() { dezibot.begin(); - Serial.begin(9600); + Serial.begin(115200); } void loop() { Serial.println("bla"); diff --git a/src/Dezibot.cpp b/src/Dezibot.cpp index a0e30c8..587bef7 100644 --- a/src/Dezibot.cpp +++ b/src/Dezibot.cpp @@ -12,7 +12,7 @@ #include "Dezibot.h" -Dezibot::Dezibot():multiColorLight(){ +Dezibot::Dezibot():multiColorLight(){}; void Dezibot::begin(void) { infraredLight.begin(); @@ -21,4 +21,4 @@ void Dezibot::begin(void) { multiColorLight.begin(); }; -}; + diff --git a/src/lightDetection/LightDetection.cpp b/src/lightDetection/LightDetection.cpp index 8fc22fd..9812d11 100644 --- a/src/lightDetection/LightDetection.cpp +++ b/src/lightDetection/LightDetection.cpp @@ -47,6 +47,7 @@ photoTransistors LightDetection::getBrightest(ptType type){ }; uint32_t LightDetection::getAverageValue(photoTransistors sensor, uint32_t measurments, uint32_t timeBetween){ + TickType_t xLastWakeTime = xTaskGetTickCount(); TickType_t frequency = timeBetween / portTICK_PERIOD_MS; uint64_t cumulatedResult = 0; @@ -58,6 +59,7 @@ uint32_t LightDetection::getAverageValue(photoTransistors sensor, uint32_t measu }; void LightDetection::beginInfrared(void){ + digitalWrite(IR_PT_ENABLE,true); pinMode(IR_PT_ENABLE, OUTPUT); pinMode(IR_PT_FRONT_ADC, INPUT); pinMode(IR_PT_LEFT_ADC, INPUT); @@ -66,13 +68,14 @@ void LightDetection::beginInfrared(void){ }; void LightDetection::beginDaylight(void){ + digitalWrite(DL_PT_ENABLE,true); pinMode(DL_PT_ENABLE, OUTPUT); pinMode(DL_PT_BOTTOM_ADC, INPUT); pinMode(DL_PT_FRONT_ADC, INPUT ); }; uint16_t LightDetection::readIRPT(photoTransistors sensor){ - digitalWrite(IR_PT_ENABLE,HIGH); + //digitalWrite(IR_PT_ENABLE,HIGH); uint16_t result = 0; switch (sensor) { @@ -91,7 +94,7 @@ uint16_t LightDetection::readIRPT(photoTransistors sensor){ default: break; } - digitalWrite(IR_PT_ENABLE,LOW); + //digitalWrite(IR_PT_ENABLE,LOW); return result; };