Demo entry 6342134

Fase 1 - 3

   

Submitted by Arnau on Jan 05, 2017 at 18:39
Language: Arduino. Code size: 1.1 kB.

#include <TimerOne.h> // Afegim la llibreria

/* Inicialitzacio de constants i variables */
int val = 0;
int angle = 0, regulador = 0; // Valor angle real, regulador
const int pinMotor = 9;
const int minPotenciometre = 0, maxPotenciometre = 371;
const int angleMin = -40, angleMax = 115;
const int minRegulador = 0, maxRegulador= 1020;

void setup(){    
    Serial.begin(9600);
    Timer1.initalize(2000);
    Timer1.attachInterrupt(interrupcio);
    pinMode(pinMotor, INPUT);
}

void loop(){
    /* Retorna el valor de l'angle per cada cicle */
    angle = analogRead(A0);
    angle = map(angle, minPotenciometre, maxPotenciometre, angleMin, angleMax);
    Serial.println(angle); // Angle real
    Serial.println((angle-angleMin)*100/angleMax); // Percent angle
    delay(100); // Deixem temps per la transmissio de dades
}

void interrupcio(){
    /* Actualitza el valor de l'angle */
    regulador = analogRead(A1); // Entrada regulador
    regulador = map(regulador, minRegulador, maxRegulador, 0, 1023); // 0 valor minim i 1023 valor maxim
    analogWrite(pinMotor, regulador);
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).