Arduino deneyi 06
Mix Colours with an RGB LED
Beginner · 45 min · PWM output
Control the red, green and blue channels of a common-cathode RGB LED.
Malzemeler
- Arduino Uno
- Common-cathode RGB LED
- 3 × 220 Ω resistors
- Breadboard and jumper wires
Bağlantı
- Connect the RGB LED common cathode to GND.
- Connect red, green and blue anodes through separate 220 Ω resistors to PWM pins 9, 10 and 11.
Kod
const int redPin = 9, greenPin = 10, bluePin = 11;
void colour(int r, int g, int b) {
analogWrite(redPin, r);
analogWrite(greenPin, g);
analogWrite(bluePin, b);
}
void setup() {
pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT);
}
void loop() {
colour(255, 0, 0); delay(1000);
colour(0, 255, 0); delay(1000);
colour(0, 0, 255); delay(1000);
colour(160, 0, 180); delay(1000);
}
Ne olmalı?
The LED cycles through three primary colours and purple.
Meydan okuma
Create orange, cyan and a smooth colour fade.
Güvenlik ve sorun giderme
- Bağlantıyı değiştirmeden önce gücü kes.
- Her LED ile direnç kullan.
- Kart ve port seçimini Arduino IDE'de kontrol et.
- Her kablonun koddaki pin numarasıyla eşleştiğini doğrula.
Not: Ders metinleri İngilizcedir. Orijinal Türkçe çalışma kâğıdı PDF olarak indirilebilir.
