導航:首頁 > 軟體知識 > 如何運行樹莓派里的程序

如何運行樹莓派里的程序

發布時間:2023-07-06 05:35:24

⑴ 樹莓派系統怎麼運行py文件

一、首先寫個簡單的python
腳本
腳本很簡單,就是樹莓派上一個燈閃爍程序
文件保存在/home/pi/script/ledblink.py

開機啟動腳本
保存腳本為/etc/init.d/ledblink文件

設置python腳本開機啟動
這樣就完工了,重啟樹莓派就會發現led自己閃爍了,停止用sudo
service
ledblink
stop就行

⑵ 已經有樹莓派程序,請問如何讓程序在樹莓派里運行呢

樹莓派中sudo是不需要密碼的。 所以原則上可以在腳本里切換成ROOT用戶。

你這個腳本做什麼用,如果只是切換完了,執行一個命令,直接用su就可以搞定,印象中是su -c。su -c USER CMD

如果你想執行完腳本後還保留在root狀態中,直接用sudo -s就可以

⑶ 使用PyCharm連接樹莓派遠程編程

這篇教程是關於如何在Windows操作系統上使用PyCharm IDE遠程連接樹莓派執行Python 2.7程序。 這篇教程環境是基於運行Windows 10電腦和運行Raspbian OS的樹莓派。
第一步 : 確認Windows電腦和樹莓派在同一個網路里。
第二步: 在你的Windows電腦上安裝PyCharm Professional Edition。
第三步: 必須獲取到樹莓派的IP地址. 打開樹莓派的終端窗口輸入以下命令: ifconfig

第九步: 配置遠程Python Interpreter。

⑷ 樹莓派怎麼運行程序pathon

前言
Raspbian的系統中包含了Python的編程環境IDE,方便了我們對於python的學習。個人覺得還是游戲程序能夠更好的激發我們的潛力所以,話不多說下面就來使用python編寫我們簡單的游戲程序吧。

儲備知識
①import 模塊:time時間模塊、random隨機數模塊
②列表:[ ] #[]中放入值,與數組很像,但是不同
③def:定義函數
④python的縮進是編程格式的一種,if等都不需要{}括起來,關鍵看縮進區分
⑤if,while,def函數都要以 「:」開始

游戲概述
一進入游戲,主人公就會隨機獲取一個游戲已經設定的道具。最開始,主人公站在叢林的邊緣,只有左右可選,左邊是個洞穴,右邊是沙灘。
選擇左邊,則開始可以獲得手電筒,但是在洞穴中會碰到蛇hp-20,繼續向下會到一個未知空間,游戲結束。
選擇右邊,會到沙灘 獲得涼爽的水hp+70,但是由於沒有游泳裝備,如果繼續選擇游泳,會遇到海嘯而死亡。

代碼
[python] view plain 在CODE上查看代碼片派生到我的代碼片
#Python Adventure Game
import time
import random

#define variable health point
hp = 30

#define variable object_ to show what the adventurer has
object_=[]

#define variable what the game sets
tools = ["Torch","Rope","Spanner","50HP","10HP"]

#set two acceptable answers ,select any one to end loop
def get_input(prompt,accepted):
while True:
value = input(prompt).lower()

if value in accepted:
return value
else :
print("That is not a recognised answer,must be one of",accepted)

def handle_room(location) :
global hp

if location== "start":
print("You are stading on a path at the edge of a jungle.There is a cave to your left and a beach to your right.")
object_.append(random.choice(tools))
print("Lucky,you have gained",object_[-1])
use_tools(object_)
direction = get_input("Do you want to go left or right?",["left","right"])

if direction == "left":
return "cave"
elif direction == "right":
return "beach"

elif location == "cave":
print("On the entrance of cave,you find a torch!!!")
object_.append("Torch")
print("You walk to the cave and notice there is an opening.")
print("A small snake bites you,and you lose 20 health points.")
hp-=20

answer = get_input("Do you want to go deeper?(y/n)",["y","n"])
if answer == "y":
return "deep_cave"
elif answer == "n":
return "start"

elif location == "beach":
print("You walk to the beach but remember you do not have any swimwming equipment.")
print("The cool water revitalizes you.You have never felt more alive,gain 70 health points.")
hp+=70

answer = get_input("Do you want to go swimming?(y/n)",["y","n"])
if answer == "y":
return "sea"
elif answer == "n":
return "start"

elif location == "sea":
print("Suddenly there was a tsunami,you can't escape.")
hp=0
return "end"

else :
print("Programmer error,room",location,"is unknown")
return "end"

#define the function to use the tools of HP
def use_tools(tool):
global hp
length = len(tool)
for i in range(0,length):
if tool[i]=="50HP":
hp+=50
tool.pop(i)
print("You have use the tool of 50HP")
j+=1
elif tool[i]=="10HP":
hp+=10
tool.pop(i)
print("You have use the tool of 10HP")
j+=1

#The begin of the program.
location = "start"

#Loop until we reach the special "end" location
while location!="end":
location = handle_room(location)

#Check we are not dead each return
print("You now have",hp,"health points.")
if hp<=0:
print("You are dead.\nGame Over!!!")
break

print("Your adventure has ended,bye~")

⑸ 如何通過筆記本電腦遠程登錄樹莓派電腦運行程序

用網線直連電腦,不經過路由器。這個方法最大的特點用最少的工具玩樹莓派。
一、材料:樹莓派一部、網線一根,筆記本電腦一台。1、樹莓派:帶供電系統和燒好Raspbian系統的SD卡;2、網線:交叉或直連

閱讀全文

與如何運行樹莓派里的程序相關的資料

熱點內容
微信清內存後小程序數據怎麼恢復 瀏覽:82
廉江中心市場屬於哪個鎮 瀏覽:946
3個鍵同時按結束程序是哪個 瀏覽:796
網店怎麼找代理商 瀏覽:447
動態交通信息服務什麼意思 瀏覽:48
什麼是單獨代理執行階段 瀏覽:620
2020年關稅配額有哪些產品 瀏覽:506
如何防止資料庫內部威脅 瀏覽:403
ug怎麼在程序里加m8 瀏覽:979
消費者如何保持產品質量 瀏覽:82
代理商怎麼聯系供應商 瀏覽:168
神之路在哪裡能交易號 瀏覽:585
技術職業學校哪裡的好 瀏覽:581
有貨找車怎麼朋友圈發布信息 瀏覽:327
抖音顏值評分小程序多少分算帥 瀏覽:278
集中資料庫有哪些 瀏覽:44
怎麼做城市欣雅紙代理 瀏覽:120
遷安有哪些證券交易所 瀏覽:673
法蘭克加工中心怎麼刪除程序名 瀏覽:497
山地車代理如何發展 瀏覽:621