attiny 85 and the ping sensor

i intend to make rbg night light using 2 attny 85s one to control the led light array and they other to act as a type of stand alone pwm signal generator hooked to the ping sensor feeding back a value to the other to change the light colors off the top of my head im thinking i have a problem the ping sensor example code uses 2 of the pwm pin of the tiny 85 up so mapping a value to send to the transistor wont be imposable right ? can any one think of another way to do this i read in another topic that i could re map the analog pin 1c of the chip to be digital but not pwm digital correct
soo will this work if the ping sensor only needs to be on a digital pin not a pwm digital pin ? thanks im going back to try trial and error method for now ! lol

the ping sensor example code uses 2 of the pwm pin

Which example code?

example code for the ping sensor from the sr04 ping device ) i found a better example im not sure where its from or who to thank it was on a google page but threw trial and eror this is what was able modified to my needs seems to be working ok with out the pwm pin im assuming it will just have a slower response time on the ping

/*
 HC-SR04 Ping distance sensor]
 VCC to arduino 5v GND to arduino GND
 Echo to Arduino pin 13 Trig to Arduino pin 12
 More info at: http://goo.gl/kJ8Gl
 */
#define trigPin PB2 // changed these to match pins that the attiny 85 has
#define echoPin PB1

int rpm = PB0; // pwm pin out to transistor to control motor and colors
int Val; //  used to map value to 255 
void setup() {

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(rpm, OUTPUT); 
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line

  digitalWrite(trigPin, HIGH);
  //  delayMicroseconds(1000); - Removed this line
  
  delayMicroseconds(10); // Added this line
  
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  
  
  
  if (distance >= 65 || distance <= 0){

    analogWrite(rpm, 0); // stop all motion and colors on leds result hall way night light dose not keep me a wake with flash 
                                 // in till it see me in range used a ping sensor as a motion detector in short
  }
  else {


     analogWrite(5,distance/4);
     
     Val = map(distance, 65, 1, 0, 80);
     analogWrite(rpm, Val);
     
     
    
  }
  
  
  
  
  
  delay(1);
}

I don't understand why need two t85 processors. Three pins for the LED. Two pins for the ping sensor. Five total pins. Should work nicely with one t85 processor.

Oh i need extra pwm pins for color transions using if statements to cordnaite pre programed colors with the reading sent from the attiny handleing the ping sensor a atmel 328 may have been a better choise but thats what i hand

Why do you need a second processor to manage the ping sensor?

Im not sure that it did ? It seemed simple tho ... Due to the fact that i needed 3 pwm pins and only had 2 avabile on the attiny85 theres 3 colors tom send values to there negitve aniodes with transistors if i dident have the extra set of pwm pins to play with i would have had solid red green and blue for colors not the smoth mix of them colors so i just deacated one chip to the ping and one to the leds and doing this another way i dont know if i would have come up with a better sulotion ? Im not vary good with the programing yet im just fidleing with example code at this point so if you think theres another way to acoplish 3pwm pins to red ,green,blue, and run a ping sensor with real time values. Im all ears buddy " ? :slight_smile: the only fact that i may be over looking on how to change the way i set this up would be can you runn the ping on the anlog pin with out. Pwm and then can the tiny 85 be changed so you would would have 3 pwm pjns instead of just 2 . That would be the only way i can think to fit this all on one chip then the program omg i dont know where to begin running thatg much code togeather .

ez8mm:
Due to the fact that i needed 3 pwm pins and only had 2 avabile on the attiny85

The ATtiny85 has three PWM pins.

Even if it didn't you could easily do it in software.

hmm i guess i was miss informed about the 3 pwm pins @ code badly i was readinhg threw the fourms and found some ones post about the third digatal pin and i read that the pb2 pin anlog pin 1 could dubble as a digatal pin with out pwm but i read threw most of this http://arduino.cc/forum/index.php/topic,87517.0.html and could not find how this is done manged it on my own do you have to do some thing to the chip to make it a pwm pin or just program it to do so like normal ?

@fungus i figuer your limataions are end less with the programing and soft ware side of things but that greek to me at this point im begining to under stand what i can in my free time

do you have to do some thing to the chip to make it a pwm pin or just program it to do so like normal ?

I know this core supports PWM on three pins...
http://code.google.com/p/arduino-tiny/

I believe the MIT HLT core also supports PWM on three pins...
http://hlt.media.mit.edu/?p=1695

Pins 0, 1, and 4 support PWM.

You can use PWM as you normally would...

  analogWrite( 0, 37 );
  analogWrite( 1, 42 );
  analogWrite( 4, 111 );