我想关掉我的Raspberry Pi的LED。
我尝试修改文件echo none >/sys/class/leds/led0/trigger
,但没有任何改变。
这可能吗?
答案 0 :(得分:24)
根据Raspberry Pi论坛:
答案 1 :(得分:19)
RaspberryMediaCenter:/sys/class/leds # echo 0 >/sys/class/leds/led1/brightness
RaspberryMediaCenter:/sys/class/leds # echo 0 >/sys/class/leds/led0/brightness
led0
绿色
led1
红色
答案 2 :(得分:3)
根据您所说的LED,看起来不可能。
有关更多信息,请阅读How can I turn the lights off on my pi?(这也是询问RPi问题的好地方)
答案 3 :(得分:2)
我意识到这是一个老问题。但是,这是我在谷歌搜索结果中的第一个,它对我的Raspberry Pi2 B +不起作用。对于像我这样现在发现这一点的人来说,http://www.jeffgeerling.com/blogs/jeff-geerling/controlling-pwr-act-leds-raspberry-pi的技术确实有效。
答案 4 :(得分:1)
在Pi上,您可以通过编辑位于以下位置的文件来控制2 Leds(红色和绿色)。
//word to solve
String keyword = "stackoverflow";
int lettersLeft = keyword.length();
//solved word to remove guessed letters from
String solved;
int lives;
int maxLives;
//what has been guessed so far
String solution;
//a lookup of all the letters already pressed
HashMap<Character,Integer> usedLetters = new HashMap<Character,Integer>();
//game status
String status;
boolean gameOn;
//stick figure drawing
PShape hangman;//the empty group
PShape[] hangmanMembers;//each part
void setup(){
size(100,100,P2D);
//intialize the group
hangman = createShape(GROUP);
hangman.addChild(createShape(LINE,20,100,20,30));
hangman.addChild(createShape(LINE,20,30,50,30));
hangman.addChild(createShape(LINE,50,30,50,35));
hangmanMembers = new PShape[]{createShape(ELLIPSE,50,35,10,10),//head
createShape(LINE ,55,45,55,50),//neck
createShape(LINE ,55,50,55,70),//body
createShape(LINE ,55,50,40,45),//left arm
createShape(LINE ,55,50,80,45),//right arm
createShape(LINE ,55,70,40,90),//left leg
createShape(LINE ,55,70,60,90)//right leg
};
//some people draw a hangman with no neck, other use more parts, make the number of lives dependant on that
maxLives = hangmanMembers.length;
lives = maxLives;//set the number of lives left
//add the dashes
solved = ""+keyword;
solution = "";
status = "";
for(int i = 0 ; i < lettersLeft; i++) solution += "_";
usedLetters.clear();
gameOn = true;
}
//render
void draw(){
background(127);
text(solution,10,15);
text(status,10,25);
shape(hangman);
}
void keyPressed(){
//if the game was not won or lost yet
if(gameOn){
//check if the key pressed is a letter
if(Character.isLetter(key)){
//check if the letter hasn't been used before
if(!usedLetters.containsKey(key)){
//if so, add to the list of used letters
usedLetters.put(key,keyCode);
//check if the word contains the letter
int index = keyword.indexOf(key);
if(index >= 0){
println(key + " is in " + keyword);
//remove the found letter from the word
solved = solved.replaceAll(""+key,"");
println("letters left: " + solved);
//update text for display
for(int i = 0 ; i < solution.length(); i++){
if(keyword.charAt(i) == key){
solution = solution.substring(0,i)+key+solution.substring(i+1);
}
}
//if all letters have been found, we have a winner
if(solved.isEmpty()) {
status = "you win!";
gameOn = false;
}
}else{//wrong letter, lose a part
int livesDiff = maxLives-lives;//work out the number of lives lost (maximum value - current)
if(livesDiff < maxLives) {//if there still is a shape to display
hangman.addChild(hangmanMembers[livesDiff]);
}
println(livesDiff);
lives--;
if(lives <= 0){
status = "game over!";
gameOn = false;
}
}
}else{
println("you've used " + key + " before");
}
}
}else{
//reset
setup();
}
}
例如,当Pi正在访问SD卡时关闭绿色指示灯的通常闪烁,您可以运行(作为管理员):
/sys/class/leds/led[num]
要打开或关闭一个LED,您可以更改亮度文件的状态(作为管理员):
echo none > /sys/class/leds/led0/trigger
这是我在Python中非常不优雅的解决方法,可以实际控制状态:
echo 1 > /sys/class/leds/led0/brightness # turn on
echo 0 > /sys/class/leds/led0/brightness # turn off