Arduino Pro Mini | 300 r |
Ultrasonic Module HC-SR04 Distance Sensor - 2 pcs | 230 r |
LED driver M5450 | 88 r |
Voltage Regulator L78M05CV | 26 r |
Photoresistor FR-764 | 16 r |
Cable channel 20x10 mm - 10 M | 100 r |
Wire 2x0.12 - 100 M (with a margin for tapes) | 190 r |
Wire 4x0.12 - 20 M (for sensors) | 60 r |
LED Strip LSP0603W15 White - 17 pieces of 30 cm | 1020 r |
Small things: textolite 15x15 cm, ferric chloride, drill 0.9 mm, PLS pin connectors, BLS connectors, heat shrink tubing, capacitors and resistors | 200 r |
The power supply unit 12B (it is the case) from the Parus 4 alarm system | Is free |
#include "lightuino3.h" #include "Ultrasonic.h" // #define TRIG_PIN 12 #define ECHO_PIN 13 // #define TRIG2_PIN 10 #define ECHO2_PIN 11 // Ultrasonic OurModuleUp(TRIG_PIN, ECHO_PIN); // Ultrasonic OurModuleDown(TRIG2_PIN, ECHO2_PIN); // pins 0, 1 used by Serial const unsigned char DataPin = 6; const unsigned char clockPin = 7; // const long lightSpacing = 280; // const long lightHold = 10000; // const long pingReadDelay = 50; // const float minBottomIn = 33.0f; const float minTopIn = minBottomIn; LightuinoSink sinks(clockPin, DataPin, 100, 4); boolean bClimbStarted = false; boolean bDescentStarted = false; int val; void setup() { Serial.begin(9600); pinMode(DataPin, OUTPUT); pinMode(clockPin, OUTPUT); delay(1000); sinks.set(0,0,0); } void loop() { val = analogRead(0); // if (val>=1020){ UltrasonicDownFire();// if(bClimbStarted) { bClimbStarted = false; bDescentStarted = false; climbLightSequence(); } else { // UltrasonicUpFire(); if(bDescentStarted) { bClimbStarted = false; bDescentStarted = false; descentLightSequence(); } } delay(pingReadDelay); } } // void UltrasonicUpFire() { if((OurModuleUp.Ranging(INC) < minTopIn) && (OurModuleUp.Ranging(INC) > 0)) { // Serial.println("Top sensor tripped."); bDescentStarted = true; } } // ] void UltrasonicDownFire() { if((OurModuleDown.Ranging(INC) < minTopIn) && (OurModuleDown.Ranging(INC) > 0)) { // Serial.println("Bottom sensor tripped."); bClimbStarted = true; } } void climbLightSequence(){ LedsOnDown(); } void LedsOnDown(){ // byte ledState[9]; for (int j=0;j<9;j++) { ledState[j] = B00000000; } // for (int k=1;k>=0;k--) { for (int j=8;j>=1;j--) { ledState[k] = (ledState[k] >> 1) + 128; sinks.set(ledState); delay(lightSpacing); } } // delay(lightHold); // for (int k=1;k>=0;k--) { for (int j=8;j>=1;j--) { ledState[k] = (ledState[k] >> 1); sinks.set(ledState); delay(lightSpacing); } } delay(pingReadDelay); } void descentLightSequence(){ LedsOnUp(); } void LedsOnUp(){ // byte ledState[9]; for (int j=0;j<9;j++) { ledState[j] = B00000000; } // for (int k=0;k<=1;k++) { for (int j=0;j<9;j++) { ledState[k]=(ledState[k] << 1) + 1; sinks.set(ledState); delay(lightSpacing); } } delay(lightHold); for (int k=0;k<=1;k++) { for (int j=0;j<9;j++) { ledState[k]=(ledState[k] << 1); sinks.set(ledState); delay(lightSpacing); } } delay(pingReadDelay); }
Source: https://habr.com/ru/post/142685/
All Articles