0% found this document useful (0 votes)
5 views4 pages

Arduino Testprogramma's

The document contains Arduino test programs for controlling LEDs, DIP switches, and a rotary encoder. It includes setup and loop functions for initializing pins and reading inputs to control the state of LEDs based on switch positions and encoder movements. The rotary encoder section also implements interrupt handling to track changes in encoder position and output the value to the serial monitor.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Arduino Testprogramma's

The document contains Arduino test programs for controlling LEDs, DIP switches, and a rotary encoder. It includes setup and loop functions for initializing pins and reading inputs to control the state of LEDs based on switch positions and encoder movements. The rotary encoder section also implements interrupt handling to track changes in encoder position and output the value to the serial monitor.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Arduino Testprogramma voor ledjes

int led1 = 2;

int led2 = 3;

int led3 = 4;

int led4 = 5;

void setup() {

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

void loop() {

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);}

Arduino Testprogramma voor ledjes en DIP switches

int led1 = 2;

int led2 = 3;

int led3 = 4;

int led4 = 5;

int scha1 =6;

int scha2 =7;

int scha3 =8;

int scha4 =9;

void setup() {

pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

pinMode(scha1, INPUT);

pinMode(scha2, INPUT);

pinMode(scha3, INPUT);

pinMode(scha4, INPUT);

void loop() {

digitalWrite(led1, digitalRead(scha1));

digitalWrite(led2, digitalRead(scha2));

digitalWrite(led3, digitalRead(scha3));

digitalWrite(led4, digitalRead(scha4));

Arduino Testprogramma voor Rotary Encoder

int encoderPin1 = 2;

int encoderPin2 = 3;

volatile int lastEncoded = 0;

volatile long encoderValue = 0;

long lastencoderValue = 0;

int lastMSB = 0;

int lastLSB = 0;

void setup() {
[Link] (9600);

pinMode(encoderPin1, INPUT);

pinMode(encoderPin2, INPUT);

digitalWrite(encoderPin1, HIGH); //turn pullup resistor on

digitalWrite(encoderPin2, HIGH); //turn pullup resistor on

//call updateEncoder() when any high/low changed seen

//on interrupt 0 (pin 2), or interrupt 1 (pin 3)

attachInterrupt(0, updateEncoder, CHANGE);

attachInterrupt(1, updateEncoder, CHANGE);

void loop(){

//Do stuff here

[Link]("EncoderValue = ");

[Link](encoderValue / 4);

delay(1000);

void updateEncoder(){

int MSB = digitalRead(encoderPin1); //MSB = most significant bit

int LSB = digitalRead(encoderPin2); //LSB = least significant bit

int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single
number

int sum = (lastEncoded << 2) | encoded; //adding it to the previous


encoded value
if((sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum ==
0b1011) && (encoderValue / 4) < 127)

encoderValue ++;

if((sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum ==


0b1000) && (encoderValue/ 4) > 0)

encoderValue --;

lastEncoded = encoded; //store this value for next time

You might also like