导航:首页 > 软件知识 > 如何运行树莓派里的程序

如何运行树莓派里的程序

发布时间: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、网线:交叉或直连

阅读全文

与如何运行树莓派里的程序相关的资料

热点内容
哪里找spss数据 浏览:345
申请的代理怎么注销 浏览:681
哪些产品有祛斑的效果 浏览:445
美国农业市场怎么样 浏览:346
换机联系方式怎么数据迁移 浏览:578
怎么注册一个品牌产品 浏览:261
抗衰老洁面产品的共性有哪些 浏览:513
北讯怎么交易不了啊 浏览:753
多道程序环境什么意思 浏览:32
有哪些奇葩的自热产品 浏览:536
有什么净水产品 浏览:474
做代理入股需要注意什么 浏览:932
什么样的数据是爆款视频 浏览:204
泰国宵夜市场有什么 浏览:592
如何核实学生餐卡的信息 浏览:975
数据库系统为什么不属于系统程序 浏览:864
白银人才市场在什么位置 浏览:500
东莞有哪些出口越南产品 浏览:288
如何开发海产品和农产品 浏览:428
c盘哪些数据可以删 浏览:617