Pages: [1]   Go Down
Author Topic: this is a good one... mind funk  (Read 803 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

basically I am moding my TV remote so that I can flick through channels quicker. ignore the project aim the mind messing comes later.

I plan to use a ATTiny 85 because of its size. I have 5 I/O's but there other stuff I want to add so be resourceful

Basically I have 1 point where I can solder too. My idea is to make 1 output pulse high and low when the button is low (when its being pressed) Something like this

If button is low {
output high
delay
output low
delay}

Excuse the code just keeping it super simple.

but How do I do this? because all i see happening is it gets stuck in a loop and just carrys on pulsing for ever...

Am I wrong or what ever?

How would you go about this... There must be a solution.

Cheers boys and girls
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34143
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
because all i see happening is it gets stuck in a loop and just carrys on pulsing for ever.
You need to post the actual code (using the # icon) so we can see where you messed up.
However look at the 'while' statement for a better approach to this problem.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
const int pulse = 2;
 
void setup() {   
 pinMode(pulse, OUTPUT);
 
}

void loop() {
 
  int buttonstate = digitalRead (pulse);
  if (buttonstate == LOW) {
    digitalWrite(pulse, HIGH); 
    delay(75);             
    digitalWrite(pulse, LOW);   
    delay(25);         
 
}}

Here it is Mike.

I am god awful at code but the way I see it if i set the pulse to pulse... it will pulse and just loop?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34143
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't use a pin as an input and an output at the same time. You have to have one pin for the input button and another for the output button. Then read the input and pulse the output for as long as the input is pushed.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
const int Pulse = 2;
 const int button = 4;
 
 
 
void setup() {   
 pinMode(Pulse, OUTPUT);
 pinMode(button, INPUT); 
 
}

void loop() {

int buttonstate = digitalRead (button); 

 while(buttonstate == LOW){
    digitalWrite(Pulse, HIGH); 
    delay(75);             
    digitalWrite(Pulse, LOW);   
    delay(25);
}}

Ok thats what I have now but it just ignores the button press and is 5v all the time even when i press the button... If i remove the ATtiny it works fine.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34143
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to read the button state inside the while loop so that when it changes you know about it.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Mike,

Code:
const int Pulse = 2;
 const int button = 4;
 
 
 
void setup() {   
 pinMode(Pulse, OUTPUT);
 pinMode(button, INPUT); 
 
}

void loop() {

  while(digitalRead(button)==LOW){
    digitalWrite(Pulse, HIGH); 
    delay(75);             
    digitalWrite(Pulse, LOW);   
    delay(25);
}}

that is what I have now smiley

But it just keeps pulsing no matter what now...

Thanks for your help so far it is very much appreciated. I don't want it doing for me but I can't get my head around it.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27081
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How is the button wired? Do you have an external pullup to 5V so it can read as  High when not pressed?
Or turn on the internal pullup:

pinMode(button, INPUT);
// add this next line to your code
digitalWrite(button, HIGH);  // enables internal pullup
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. On my breadboard it works perfectly but on the remote it doesn't. Again it just keeps pulsing.

The schematic is simple the 1 solder point I have available on the PCB. It has 2 wires coming off, one to each pin.

I thought it was an electronics problem rather than programming. If I have 1 pin pulsing low and high and one looking for the low (when the button is pressed) surely no matter what it will just go into a dirty loop?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34143
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When connecting two devices there must be a common ground, you can't just connect the signals.

Also you can not have a wire acting as an input and an output at the same time. If you only have one solder point you only have one signal, it can't be a control input and an output.
« Last Edit: May 11, 2011, 04:21:03 pm by Grumpy_Mike » Logged

Pages: [1]   Go Up
Jump to: