Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#define INTERVAL 1000 #define P_TURN 10 // en pour mille #define PINDIR1 4 #define PINPWM1 5 #define PINDIR2 2 #define PINPWM2 3 #define PINTRIG 12 #define PINECHO 11 /* Constantes pour le timeout */ const unsigned long MEASURE_TIMEOUT = 25000UL; // 25ms = ~8m à 340m/s typedef struct { bool far_l, far_r, close_l, close_r; } IR_Capture; typedef enum { INIT, RUN, LEFT, RIGHT, PAUSE, STOP } State ; typedef enum { L, R } Direction; bool line_l, line_r; // ligne sur la gauche/droite (capteur infrarouge) bool obstacle_f; // obstacle devant (capteur ultrason) bool turn, turn_l; // y a une proba de tourner au cours de la course (marche aléatoire), et une proba pour savoir si on tourne à gauche ou droite bool setting_up, fatal_error, success, start; int speedL=0; int speedR=0; double prop =1.100; bool led=false; int vit=50; State state; void setup() { // port série Serial.begin(115200); //on initialise les pins du moteur 1 pinMode(PINDIR1, OUTPUT); pinMode(PINPWM1, OUTPUT); pinMode(PINDIR2, OUTPUT); pinMode(PINPWM2, OUTPUT); digitalWrite(PINDIR1,LOW); digitalWrite(PINDIR2,LOW); pinMode(PINTRIG, OUTPUT); digitalWrite(PINTRIG, LOW); // La broche TRIGGER doit être à LOW au repos pinMode(PINECHO, INPUT); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); state=INIT; } IR_Capture detect_IR() { // capteurs infrarouges IR_Capture cap; return cap; } void detect_US() { // capteurs ultrasons digitalWrite(PINTRIG, HIGH); delayMicroseconds(10); digitalWrite(PINTRIG, LOW); long measure = pulseIn(PINECHO, HIGH, MEASURE_TIMEOUT); Serial.println(measure); obstacle_f = (measure!=0 && measure<2000); } void refresh() { // met à jour les globals (conditions) detect_IR(); detect_US(); turn = (random(1000)<P_TURN); turn_l = (random(2)==0); } void transition() { if (fatal_error || success) { state = STOP; return; } switch (state) { case INIT: if (setting_up) { state = INIT; } else { if (!obstacle_f && !line_l && !line_r && !turn) { state = RUN; } else if (turn && turn_l) { state = LEFT; } else if (turn && !turn_l) { state = RIGHT; } else { state = PAUSE; } } break; case RUN: if (!line_l && !line_r && !turn && !obstacle_f) { state = RUN; } else if (line_r || (!line_l && !line_r && turn && turn_l) && !obstacle_f) { state = LEFT; } else if (line_l || (!line_l && !line_r && turn && !turn_l) && !obstacle_f) { state = RIGHT; } else if (obstacle_f) { state = PAUSE; } else { state = STOP; } break; case LEFT: if (!line_l && !line_r && !obstacle_f) { state = RUN; } else if (line_l || line_r && !obstacle_f) { state = LEFT; } else if (obstacle_f) { state = PAUSE; } else { state = STOP; } break; case RIGHT: if (!line_l && !line_r && !obstacle_f) { state = RUN; } else if (line_l || line_r && !obstacle_f) { state = RIGHT; } else if (obstacle_f) { state = PAUSE; } else { state = STOP; } break; case PAUSE: if (!line_l && !line_r && !obstacle_f) { state = RUN; } else if (line_r && !obstacle_f) { state = LEFT; } else if (line_l && !obstacle_f) { state = RIGHT; } else if (obstacle_f) { state = PAUSE; } break; case STOP: if (start) { state = INIT; } else { state = STOP; } break; default: state = STOP; break; } } void loop() { // put your main code here, to run repeatedly: unsigned long t0=millis(); refresh(); transition(); //vit=(vit+7)%255; //speedL=250; switch (state) { case INIT: Serial.println(F("INIT")); state=RUN; break; case RUN: Serial.println(F("RUN")); led=true; speedL=vit; speedR=vit; break; case LEFT: Serial.println(F("LEFT")); led=true; speedL=0; speedR=vit; break; case RIGHT: Serial.println(F("RIGHT")); led=true; speedL=vit; speedR=0; break; case PAUSE: Serial.println(F("PAUSE")); led=false; speedL=0; speedR=0; break; case STOP: Serial.println(F("STOP")); led=false; speedL=0; speedR=0; break; default: break; } analogWrite(PINPWM1,digitalRead(!PINDIR1 )?(int)(prop*speedL):(int)prop*(255-prop*speedL)); analogWrite(PINPWM2,digitalRead(!PINDIR2 )?speedR:255-speedR); digitalWrite(LED_BUILTIN, (led)?HIGH:LOW); //Serial.print(F("Current state: ")); //Serial.println(state); unsigned long elapsed=millis()-t0; if (elapsed>INTERVAL) printf("Excessive execution time\n"); else delay(INTERVAL-elapsed); }
Optional Paste Settings
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
Проверка на спелув...
Java | 19 min ago
09.PadawanEquipmen...
Java | 25 min ago
My Log File
HTML 5 | 44 min ago
Internet Downloade...
Python | 49 min ago
Фреквентен стринг
Java | 1 hour ago
Star Mart
Lua | 1 hour ago
Untitled
C# | 1 hour ago
YouTube Downloader...
Python | 1 hour ago
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!