Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include <Arduino.h> // PIN CONSTANTS const byte PIN_LED = 13; // Pin 13 has an LED connected on most Arduino boards. const byte PIN_LDR_UP = A0; // LDR ülesse poole paneeli const byte PIN_LDR_DOWN = A1; // LDR alla poole paneeli const byte PIN_LIMIT_UP = A2; // lääne lõpu lüliti.Peab olema high lõpus low. Kui valgus langeb määratud tasemele-LDR_NIGHT siis pöörab itta? const byte PIN_LIMIT_DOWN = A3; // ida lõpu lüliti.peab olema high.Lõpus low.Et ei hakkaks enam pöörama itta. Nii riist- kui tarkvaraliselt const byte PIN_MOTOR_DRIVE_UP = 7;// OUT 1 h-bridge const byte PIN_MOTOR_DRIVE_DOWN = 8;// OUT 2 h-bridge vahetada OUT 1-ga kui pöörab valele poole // LOGIC CONSTANTS const byte LDR_DEAD_BAND = 30; // erinevus LDR-de vahel, et hakkaks pöörama const byte LDR_NIGHT = 1; // väärtus, et on pime ja paneel sõidaks itta ? const int LDR_INTERVAL = 100; // check LDR every x milliseconds const int MOTOR_STOP = 0; // 0 to motor_control will stop motors const int MOTOR_UP = 255; // Amplitude = PWM, sign = direction const int MOTOR_DOWN = -255; // Amplitude = PWM, sign = direction const int MOTOR_INTERVAL = 500; // update motor controls every x milliseconds const int PRINT_INTERVAL = 1000; // print status to serial interface every x milliseconds // GLOBALS unsigned long timeMotor = 0; unsigned long timeLDR = 0; unsigned long timePrint = 0; int ldrDown = 0; int ldrUp = 0; int motor_direction = 0; // light dependant resistor measurememt function // expects a byte containing the pin to read // read the analog value of the pin several times, filtering the value to be more repeatable // protection: check the value of the pin is not full scale or zero, indicating a sensor error // if protection invoked, return an error message // otherwise return the result int read_ldr(byte pin) { int ldr_average = analogRead(pin); for (byte i = 0; i < 5; i++) { int value = analogRead(pin); // if (value == 0 || value == 1023) // return -1; ldr_average += value; // ldr_average = ldr_average + value; ldr_average /= 2; // ldr_average = ldr_average / 2; } return ldr_average; } // motor control function // expects a signed integer to define direction and duty to drive the motor // if the parameter is out of range or zero then we stop motors // if the parameter is greater than zero we drive to the west // if the parameter is less than zer we drive to the east // protection: we don't drive in the direction of a limit switch, when it is active. // returns what happened int motor_control(int dir) { // stop condition digitalWrite(PIN_LED, LOW); if (dir == 0 || dir > 255 || dir < -255) { // stop motors //digitalWrite(PIN_MOTOR_ENABLE, LOW); digitalWrite(PIN_MOTOR_DRIVE_DOWN, LOW); digitalWrite(PIN_MOTOR_DRIVE_UP, LOW); motor_direction = MOTOR_STOP; digitalWrite(PIN_LED, HIGH); return 0; } // greater than zero -> drive UP if (dir > 0) { // if on Up limit or driving Down (<0), stop if (digitalRead(PIN_LIMIT_UP) || motor_direction < 0) { motor_control(MOTOR_STOP); return 2; } // drive UP digitalWrite(PIN_MOTOR_DRIVE_UP, HIGH); motor_direction = MOTOR_UP; return 1; } // less than zero -> drive Down if (dir < 0) { // if Down limit or currently driving west (>0), stop if (digitalRead(PIN_LIMIT_DOWN) || motor_direction > 0) { motor_control(MOTOR_STOP); return -2; } // drive Down digitalWrite(PIN_MOTOR_DRIVE_DOWN, HIGH); //digitalWrite(PIN_MOTOR_DRIVE_UP, HIGH); motor_direction = MOTOR_DOWN; return -1; } } // the setup routine runs once when you press reset: void setup() { // digital outputs pinMode(PIN_LED, OUTPUT); // digital pwm outputs pinMode(PIN_MOTOR_DRIVE_DOWN, OUTPUT); pinMode(PIN_MOTOR_DRIVE_UP, OUTPUT); // analog inputs pinMode(PIN_LDR_DOWN, INPUT); pinMode(PIN_LDR_UP, INPUT); // digital inputs pinMode(PIN_LIMIT_DOWN, INPUT); pinMode(PIN_LIMIT_UP, INPUT); digitalWrite(PIN_LIMIT_DOWN, HIGH); // enable internal pull-up resistor digitalWrite(PIN_LIMIT_UP, HIGH); // enable internal pull-up resistor Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { unsigned long time = millis(); // check LDRs if (timeLDR <= time) { timeLDR = time + LDR_INTERVAL; ldrDown = read_ldr(PIN_LDR_DOWN); ldrUp = read_ldr(PIN_LDR_UP); } // do motor control if (timeMotor <= time) { timeMotor = time + MOTOR_INTERVAL; if (ldrDown < 0 || ldrUp < 0) { // stop everything // wait 1 minute // continue motor_control(MOTOR_STOP); Serial.print("Motor stop"); timeMotor = time + 6000; motor_control(MOTOR_DOWN); Serial.print("Pöörame ALLA"); delay(5000); } else { // main operation if (abs(ldrDown - ldrUp) < LDR_DEAD_BAND && ldrDown > LDR_NIGHT && ldrUp > LDR_NIGHT) motor_control(MOTOR_STOP); else if (ldrDown < ldrUp) // when west is more illuminated than east motor_control(MOTOR_UP); else if (ldrUp < ldrDown) motor_control(MOTOR_DOWN); else if (ldrDown < LDR_NIGHT && ldrUp < LDR_NIGHT) motor_control(MOTOR_DOWN); } } // print to serial interface if (timePrint <= time) { timePrint = time + PRINT_INTERVAL; byte limitDown = digitalRead(PIN_LIMIT_DOWN); byte limitUp = digitalRead(PIN_LIMIT_UP); Serial.print("Lower LDR, "); Serial.print(ldrDown, DEC); Serial.print(",Upper LDR, "); Serial.print(ldrUp, DEC); Serial.print(",End switch E-W, "); Serial.print(limitDown); Serial.print(","); Serial.print(limitUp); Serial.print(",Drive, "); Serial.print(motor_direction, DEC); // Serial.print(",Panel,"); Serial.println(); } }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Earn money on Changelly
CSS | 11 min ago | 0.32 KB
SwapEngine Bug [build 1.3]
25 min ago | 0.32 KB
December smells like money
CSS | 39 min ago | 0.32 KB
✅ Changelly.com Exploit
54 min ago | 0.32 KB
SelectionEdit.pas
Delphi | 8 hours ago | 27.66 KB
SelectionEdit.h
C++ | 8 hours ago | 1.42 KB
SelectionEdit.cpp
C++ | 8 hours ago | 17.22 KB
PackageRelease.ps1
PowerShell | 8 hours ago | 24.87 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!