Arduino 入门学习笔记2 三色LED实验

版权声明:(谢厂节的博客)博主文章绝大部分非原创,转载望留链接。 https://blog.csdn.net/xundh/article/details/83690856

电路

在这里插入图片描述

程序:

/***************************************************
name:RGB LED
****************************************************/

int redPin = 11;    // select the pin for the red LED
int greenPin = 10;    // select the pin for the blueLED
int bluePin = 9;

void setup() 
{
  pinMode(redPin, OUTPUT); //set redPin as OUTPUT
  pinMode(greenPin, OUTPUT);//set greenPin as OUTPUT
  pinMode(bluePin,OUTPUT);
  Serial.begin(9600);
}

void loop(){
  color(0,255,255);
  delay(1000);
  color(255,0,255);
  delay(1000);
  color(255,255,0);
  delay(1000);

  color(0,255,255);
  delay(1000);
  color(0,128,255);
  delay(1000);
  color(0,0,255);
  delay(1000);
  color(255,0,255);
  delay(1000);
  color(255,255,0);
  delay(1000);
  color(255,0,0);
  delay(1000);
  color(128,255,0);
  delay(1000);
}

void color(unsigned char red,unsigned char green,unsigned char blue)
{
  analogWrite(redPin,red);
  analogWrite(bluePin,blue);
  analogWrite(greenPin,green);
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xundh/article/details/83690856