查看“Control Led Brightness”的源代码
←
Control Led Brightness
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{Language | 控制led亮度}} {| style="width: 800px;" |- | ==Objective== This tutorial will teach you how to control LED's brightness via Processing. ==Equipment== *'''[[Microduino-Core]]''' *'''[[Microduino-FT232R]]''' *Other equipment **USB cable one **LED one **330Ω resistor one **Bread one **Breadboard Jumper onebox ==Schematic== [[File:processingControlLEDBrightness原理图.jpg|600px|center|thumb]] ==Program== https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/LEDBrightness Note:Don't drop the picture in program ==Debug== Step 1:Set up hardware system, as follows: [[File:processingControlLEDBrightness连接图.jpg|600px|center|thumb]] Step 2:Explain the code: The following code's function is that move the mouse on x position, the brightness of picture and LED will change accordingly. void draw() { loadPixels(); // We must also call loadPixels() on the PImage since we are going to read its pixels. img.loadPixels(); for (int x = 0; x < img.width; x++ ) { for (int y = 0; y < img.height; y++ ) { // Calculate the 1D pixel location int loc = x + y*img.width; // Get the R,G,B values from image float r = red (img.pixels[loc]); float g = green (img.pixels[loc]); float b = blue (img.pixels[loc]); // We calculate a multiplier ranging from 0.0 to 8.0 based on mouseX position. // That multiplier changes the RGB value of each pixel. float adjustBrightness = ((float) mouseX / width) * 8.0; r *= adjustBrightness; g *= adjustBrightness; b *= adjustBrightness; // The RGB values are constrained between 0 and 255 before being set as a new color. r = constrain(r,0,255); g = constrain(g,0,255); b = constrain(b,0,255); // Make a new color and set pixel in the window color c = color(r,g,b); pixels[loc] = c; } } updatePixels(); //output r value to ledpin arduino.analogwrite(ledPin, int(r)); } Step 3: Compile the code and download it. Step 4: The mouse lateral movement on the LED, observe the result. ==Result== The mouse is on the left, got the darkest LED, on the right side, got the brightest LED, along with the gradual change from left to right, the effect of the processing as follows: Mouse on the left: [[File:processingOverLEDBrightness1.jpg|600px|center|thumb]] Mouse in the middle: [[File:processingOverLEDBrightness2.jpg|600px|center|thumb]] Mouse on the right: [[File:processingOverLEDBrightness3.jpg|600px|center|thumb]] ==Video== |}
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
Control Led Brightness
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息