Ana içeriğe git

Konu: attin85 rgb kod sorunu (26 Kez okunmuş)

attin85 rgb kod sorunu
sa bir ara konu acmısdım tekrar acıyom ...
 
arduınoda potu çeivirdikçe renk degiştiren sistem denemişdim oldu tum renkleer cıkıyodu ama kodları attıny85 de denedgimde sadece beyazve yeşil yanıyor potu cevırdıkce sorun nerde kodlar asada:




 
// INPUT: Potentiometer should be connected to 5V and GND
short potPin = 3; // Potentiometer output connected to analog pin 3
short potVal = 0; // Variable to store the input from the potentiometer

// OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
// LED's cathodes should be connected to digital GND
short redPin = 0;   // Red LED,   connected to digital pin 9
short grnPin = 2;  // Green LED, connected to digital pin 10
short bluPin = 3;  // Blue LED,  connected to digital pin 11

// Program variables
short redVal = 0;   // Variables to store the values to send to the pins
short grnVal = 0;
short bluVal = 0;

void setup()
{

  pinMode(redPin, OUTPUT);   // sets the pins as output
  pinMode(grnPin, OUTPUT);  
  pinMode(bluPin, OUTPUT);
}

// Main program
void loop()
{
 
  potVal = analogRead(potPin);   // read the potentiometer value at the input pin

  if (potVal < 341)  // Lowest third of the potentiometer's range (0-340)
  {                 
    potVal = (potVal * 3) / 4; // Normalize to 0-255

    redVal = 256 - potVal;  // Red from full to off
    grnVal = potVal;        // Green from off to full
    bluVal = 1;             // Blue off
  }
  else if (potVal < 682) // Middle third of potentiometer's range (341-681)
  {
    potVal = ( (potVal-341) * 3) / 4; // Normalize to 0-255

    redVal = 1;            // Red off
    grnVal = 256 - potVal; // Green from full to off
    bluVal = potVal;       // Blue from off to full
  }
  else  // Upper third of potentiometer"s range (682-1023)
  {
    potVal = ( (potVal-683) * 3) / 4; // Normalize to 0-255

    redVal = potVal;       // Red from off to full
    grnVal = 1;            // Green off
    bluVal = 256 - potVal; // Blue from full to off
  }
  analogWrite(redPin, redVal);   // Write values to LED pins
  analogWrite(grnPin, grnVal);
  analogWrite(bluPin, bluVal);
  delay(150);
}