Rollanddie
Newbie level 4
Hi everyone! I'm new to programming and would like to seek the advice of you guys here
Currently I'm on a project to make up to 4 motors run and up to 4 LEDs to light up concurrently. My program is as follows:
Those in BOLD tags is what I need help with. Can I use a same switch to control both the LED and motor?
Using a simple DC motor with 5V, GND, MF, MR
- - - Updated - - -
Appreciate any inputs!
Currently I'm on a project to make up to 4 motors run and up to 4 LEDs to light up concurrently. My program is as follows:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 #include <p18f4520.h> #include <delays.h> #pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF #pragma config PBADEN = OFF #define S0 PORTCbits.RC0 #define S1 PORTCbits.RC1 #define S2 PORTCbits.RC2 void main(void) { TRISD = 0x00; //output TRISC = 0xff; //input PORTD = 0b00001111; while(1) {PORTD = 0x00; if((S0==1)&&(S1==0)&&(S2==0)) { PORTD = 0b00000001; //led 0 to light up [B](Motor 1 to run)[/B] } else if((S0==0)&&(S1==1)&&(S2==0)) { PORTD = 0b00000011; //led 0,1 to light up [B](Motor 1&2 to run)[/B] } else if((S0==1)&&(S1==1)&&(S2==0)) { PORTD = 0b00000111; //led 0,1,2 to light up [B](Motor 1&2&3 to run)[/B] } else if((S0==0)&&(S1==0)&&(S2==1)) { PORTD = 0b00001111; //led 0,1,2,3 to light up [B](Motor 1&2&3&4 to run)[/B] } } }
Those in BOLD tags is what I need help with. Can I use a same switch to control both the LED and motor?
Using a simple DC motor with 5V, GND, MF, MR
- - - Updated - - -
Appreciate any inputs!
Last edited: