Question
i need two seprite codes for ardrino . 1. Shift Registers: Upload the Code Sample 1.1 Hello World to demonstrate that the hardware is correctly
i need two seprite codes for ardrino .
1. Shift Registers:
Upload the Code Sample 1.1 Hello World to demonstrate that the hardware is correctly connected.
Modify the code sample to display a bouncing led on the leds. Light up one LED then turn it off and light up the next LED until you reach the end then repeat going the other direction. Add and use a potentiometer to control the speed of the animation.
_____________________________________________________________________________________________________________________________________
2. Rotary Encoders: Keep the same circuit used in part 1 of the lab with all 8 LEDs connected. Add the rotary encoder. Connect encoder pins to the arduino in the following way:
SW to pin 2
CLK to pin 3
DT to pin 4
(+ and GND to 5V and Ground respectively)
Upload the following example code to confirm that the encoder is working properly, you should be able to open the arduino serial monitor and see the number increase and decrease as you turn the knob back and forth
#define encoder0PinA 3 #define encoder0PinB 4 volatile byte encoder0Pos = 0; void setup() { pinMode(encoder0PinA, INPUT); digitalWrite(encoder0PinA, HIGH); // turn on pull-up resistor pinMode(encoder0PinB, INPUT); digitalWrite(encoder0PinB, HIGH); // turn on pull-up resistor attachInterrupt(digitalPinToInterrupt(encoder0PinA), doEncoder, CHANGE); // encoder pin
Serial.begin (9600); } void loop() { // do some stuff here - the joy of interrupts is that they take care of themselves
Static byte oldEncoderPos = 0;
if (oldEncoderPos != encoder0Pos) {
oldEncoderPos = encoder0Pos;
Serial.println (encoder0Pos, DEC); // Print the value when the number changes
}
} void doEncoder() { // If pinA and pinB are both high or both low, it is spinning // CW. If they're different, it's going CCW. if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) { encoder0Pos++; } else { encoder0Pos--; } }
Combine the sample code above with the shift register code from part one and output the binary number of the encoder position to the LEDs. Consider each led as an individual bit in a byte and the position number byte should illuminate the appropriate LEDs
What happens if you keep turning the knob after all of the LEDs are illuminated?
__________________________________________________________________________
Why?______________________________________________________________________
__________________________________________________________________________
Add some code to make it so that if you kept turning the knob clockwise the LEDs would eventually all be illuminated and they will all stay illuminated even if you keep turning the knob. The same code should also make it so that if you keep turning the knob counter-clockwise the LEDs would all turn off and stay turned off even if you keep turning the knob.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started