0% found this document useful (0 votes)
53 views3 pages

Annexe: Programme Du Microcontrôleur

This Arduino code controls a DC motor using a microcontroller and LCD display. It implements three modes: initial state, forward direction, and reverse direction. The forward and reverse modes allow changing the motor speed using buttons to adjust an alpha value that determines the on/off timing. Buttons also allow switching between modes or stopping the motor. The LCD displays the selected mode, motor direction, and alpha value.

Uploaded by

SoufianeBattal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Annexe: Programme Du Microcontrôleur

This Arduino code controls a DC motor using a microcontroller and LCD display. It implements three modes: initial state, forward direction, and reverse direction. The forward and reverse modes allow changing the motor speed using buttons to adjust an alpha value that determines the on/off timing. Buttons also allow switching between modes or stopping the motor. The LCD displays the selected mode, motor direction, and alpha value.

Uploaded by

SoufianeBattal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ANNEXE :

void loop() {
Programme du microcontrleur :
//////////////////////// test des boutons

#include <LiquidCrystal.h>
Testbouton();
LiquidCrystal lcd(12,11, 5, 4, 3, 2);

float periode=500;
//////////////////////// les modes de
float alpha=0; fonctionement
float alpha2=0; switch (mode) {
float valeur=0; //////////////////////// etat initiale
float Ton=0; case 0: {
int mode=0; if(digitalRead(STOP)==1){
int STOP=13; sensdirect();
int sensdirectbtn=7; }
int sensinversebtn=6; else{
int plus=15; mode=0;
int moins=14; lcd.clear();
void setup() { stopmoteur();}}
// put your setup code here, to run once: break;
lcd.begin(16, 4); //////////////////////// mode direct
pinMode(9,OUTPUT); case 1: {
pinMode(8,OUTPUT); if(digitalRead(STOP)==1){
pinMode(6,INPUT); sensdirect(); }
pinMode(7,INPUT); else{ mode=0;
pinMode(14,INPUT); Ton=0;
pinMode(15,INPUT); lcd.clear();
digitalWrite(9,LOW); stopmoteur();}}
digitalWrite(8,LOW); break;
Serial.begin(9600);}
//////////////////////// mode direct digitalWrite(9, HIGH);

case 2: {// mode inverse delay(Ton);

if(digitalRead(STOP)==1){ digitalWrite(9, LOW);

sensinverse(); delay(periode-Ton);

} Testbouton();

else{ }

mode=0; }

Ton=0; void sensinverse(){

lcd.clear(); while(mode==2 && digitalRead(STOP)==1 ){

stopmoteur();}} lcd.clear();

break; lcd.setCursor(0, 0);

default: lcd.print(" ## Variateur ##");

break; lcd.setCursor(1, 1);

}} lcd.print("Sens inverse");

void sensdirect(){ valeur=alphabtn(valeur);

while(mode==1 && digitalRead(STOP)==1 ){ alpha2=map(valeur,0,10,0,5);

lcd.clear(); alpha=alpha2/10;

lcd.setCursor(0, 0); Ton=periode*(alpha);

lcd.print(" ## Variateur ##"); lcd.setCursor(1, 2);

lcd.setCursor(1, 1); lcd.print("Ton :");

lcd.print("Sens direct"); lcd.setCursor(7, 2);

valeur=alphabtn(valeur); lcd.print(alpha);

alpha2=map(valeur,0,10,5,10); digitalWrite(8, HIGH);

alpha=alpha2/10; delay(Ton);

Ton=periode*(alpha); digitalWrite(8, LOW);

lcd.setCursor(1,2); delay(periode-Ton);

lcd.print("alpha :"); Testbouton();

lcd.setCursor(7, 2); }}

lcd.print(alpha);
void stopmoteur(){

digitalWrite(8,LOW);

digitalWrite(9,LOW);

lcd.setCursor(0,0);

lcd.print("Stop");

delay(1000);

int alphabtn(int a){

if(digitalRead(moins)==0){

if(a>0){a=a-1;}

if(digitalRead(plus)==0){

if(a<10){a=a+1;}

return a;

void Testbouton(){

if(digitalRead(sensdirectbtn)==0){

delay(200);

mode=1;

if(digitalRead(sensinversebtn)==0){

delay(200);

mode=2;

You might also like