ATMega328 Programming Problems!

Status
Not open for further replies.

Unmesh Sawant

Junior Member level 2
Joined
Apr 5, 2014
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
india
Activity points
189
Hello,
I am writing a programme for a sequential circuits I am doing a very basic programme but since i am new to it, its getting complicated please help me out.
I am trying to programme atmega 328 so that i can use its 6 pins(output) and 1 Pin as input from switch but i want to use a set of these 2 . I mean 6 pins and 1 input for first and another 6 pins and 1 input for second can i run different things in one programe.

MY plan is to built a turn signal circuit a left and right so for that i need this {6 pins for lights and 1 input from switch for turning LEFT }and another 6 pins and 1 pin for turning RIGHT . also i need to assign them in sequence i.e 1&2, 3&4, 5&6 for left and 7&8, 9&10, 11&12.
I will use anolog pins as input from switch. Please help me in writhing the progamme or please send the programme if possible i need it serously

Thanks in Advance
 

You want to turn ON 1st 6 Leds when button 1 is pressed and another 6 Leds when button 2 in pressed ? If yes, You External Interrupt pins for buttons and any other pins for LEDs. If this is what you want then I can write a sketch for you.

Try this sketch.

Pins connected to D2 and D3 will be low when button not pressed and high when buttons pressed.

Code:
int Led1a = A0;
int Led2a = A1;
int Led3a = A2;
int Led4a = A3;
int Led5a = A4;
int Led6a = A5;

int Led1b = 8;
int Led2b = 9;
int Led3b = 10;
int Led4b = 11;
int Led5b = 12;
int Led6b = 13;

void setup()
{
  pinMode(Led1a, OUTPUT);
  pinMode(Led2a, OUTPUT);
  pinMode(Led3a, OUTPUT);
  pinMode(Led4a, OUTPUT);
  pinMode(Led5a, OUTPUT);
  pinMode(Led6a, OUTPUT);
  
  pinMode(Led1b, OUTPUT);
  pinMode(Led2b, OUTPUT);
  pinMode(Led3b, OUTPUT);
  pinMode(Led4b, OUTPUT);
  pinMode(Led5b, OUTPUT);
  pinMode(Led6b, OUTPUT);
  
  attachInterrupt(0, TurnOn1, RISING);
  attachInterrupt(1, TurnOn2, RISING);
}

void loop()
{  
}

void TurnOn1()
{
  digitalWrite(Led1b, LOW);
  digitalWrite(Led2b, LOW);
  digitalWrite(Led3b, LOW);
  digitalWrite(Led4b, LOW);
  digitalWrite(Led5b, LOW);
  digitalWrite(Led6b, LOW);
  
  digitalWrite(Led1a, HIGH);
  digitalWrite(Led2a, HIGH);
  digitalWrite(Led3a, HIGH);
  digitalWrite(Led4a, HIGH);
  digitalWrite(Led5a, HIGH);
  digitalWrite(Led6a, HIGH);
}

void TurnOn2()
{ 
  digitalWrite(Led1a, LOW);
  digitalWrite(Led2a, LOW);
  digitalWrite(Led3a, LOW);
  digitalWrite(Led4a, LOW);
  digitalWrite(Led5a, LOW);
  digitalWrite(Led6a, LOW);
  
  digitalWrite(Led1b, HIGH);
  digitalWrite(Led2b, HIGH);
  digitalWrite(Led3b, HIGH);
  digitalWrite(Led4b, HIGH);
  digitalWrite(Led5b, HIGH);
  digitalWrite(Led6b, HIGH);
}
 
Last edited:

Also you can use one pin for 6 or more LEDs. You have to use a 2N2222A transistor and connect LEDs in series or series parallel combination and drive more than 6 leds.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…