SlideShare a Scribd company logo
1 of 1
#include <mechbotShield.h>
#include <avr/io.h>
int main(void) {
//set the port direction for switch S1 & S2, 0 for input
DDRD &= ~((1<<PD3) | (1<<PD4));
//pull the internal resistor high
PORTD |= (1<<PD3) | (1<<PD4);
//setup the LEDs, 1 for output
DDRB |= 0b00111111;
DDRD |= (1<<PD6) | (1<<PD7);
//set the LEDs all to off
PORTB |= 0b00000000;
PORTD &= ~((1<<PD6) | (1<<PD7));
PORTB = 0b00000001;
while (1) {
//read the port and test for switch S1 & S2 on PIND
//buttons go low when pushed (ie. normally pulled hi)
/* Going down*/
if( PORTB != 0b00000001){
if ((PIND & (1<<PD3)) == 0) {
if(PORTB==0b10000000) {
PORTD&=~(1<<PD7);
PORTD|=(1<<PD6);
}
else if(PORTB==0b01000000){
PORTD&=~(1<<PD6);
}
PORTB = PORTB >> 1;
}
}
/* Going up*/
if( PORTB != 0b10000000){
if ((PIND & (1<<PD4)) == 0){
if(PORTB==0b00100000) {
PORTD&=~(1<<PD7);
PORTD|=(1<<PD6);
}
else if(PORTB==0b01000000){
PORTD&=~(1<<PD6);
PORTD|=(1<<PD7);
}
PORTB = PORTB << 1;
}
}
delay_ms(200);
} //end while
} //end main

More Related Content

Similar to Flicking LED C code

Mims effect
Mims effectMims effect
Mims effect
arnaullb
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
forwardcom41
 
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
SANTIAGO PABLO ALBERTO
 

Similar to Flicking LED C code (20)

Controlling Motors for Robot
Controlling Motors for RobotControlling Motors for Robot
Controlling Motors for Robot
 
Mims effect
Mims effectMims effect
Mims effect
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
Arduino final ppt
Arduino final pptArduino final ppt
Arduino final ppt
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
LED
LEDLED
LED
 
Arduino Workshop 2011.05.31
Arduino Workshop 2011.05.31Arduino Workshop 2011.05.31
Arduino Workshop 2011.05.31
 
Microcontroller avr
Microcontroller avrMicrocontroller avr
Microcontroller avr
 
Ir remote kit_blink.pde
Ir remote kit_blink.pdeIr remote kit_blink.pde
Ir remote kit_blink.pde
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshop
 
Program LCD ARM
Program LCD ARMProgram LCD ARM
Program LCD ARM
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arm7 Interfacing examples
Arm7   Interfacing examples Arm7   Interfacing examples
Arm7 Interfacing examples
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
 
HT12A.PDF
HT12A.PDFHT12A.PDF
HT12A.PDF
 
HT12A.PDF
HT12A.PDFHT12A.PDF
HT12A.PDF
 
EEE UNIT-2 PPT.pdf
EEE UNIT-2 PPT.pdfEEE UNIT-2 PPT.pdf
EEE UNIT-2 PPT.pdf
 
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 

Flicking LED C code

  • 1. #include <mechbotShield.h> #include <avr/io.h> int main(void) { //set the port direction for switch S1 & S2, 0 for input DDRD &= ~((1<<PD3) | (1<<PD4)); //pull the internal resistor high PORTD |= (1<<PD3) | (1<<PD4); //setup the LEDs, 1 for output DDRB |= 0b00111111; DDRD |= (1<<PD6) | (1<<PD7); //set the LEDs all to off PORTB |= 0b00000000; PORTD &= ~((1<<PD6) | (1<<PD7)); PORTB = 0b00000001; while (1) { //read the port and test for switch S1 & S2 on PIND //buttons go low when pushed (ie. normally pulled hi) /* Going down*/ if( PORTB != 0b00000001){ if ((PIND & (1<<PD3)) == 0) { if(PORTB==0b10000000) { PORTD&=~(1<<PD7); PORTD|=(1<<PD6); } else if(PORTB==0b01000000){ PORTD&=~(1<<PD6); } PORTB = PORTB >> 1; } } /* Going up*/ if( PORTB != 0b10000000){ if ((PIND & (1<<PD4)) == 0){ if(PORTB==0b00100000) { PORTD&=~(1<<PD7); PORTD|=(1<<PD6); } else if(PORTB==0b01000000){ PORTD&=~(1<<PD6); PORTD|=(1<<PD7); } PORTB = PORTB << 1; } } delay_ms(200); } //end while } //end main