forked from M-Labs/artiq
1
0
Fork 0
artiq/examples/coredev_test.py

39 lines
912 B
Python
Raw Normal View History

2014-08-13 18:30:57 +08:00
from artiq.language.core import AutoContext, kernel
from artiq.devices import corecom_serial, core, gpio_core
2014-07-06 04:48:27 +08:00
2014-09-05 12:03:22 +08:00
2014-08-13 18:30:57 +08:00
class CompilerTest(AutoContext):
2014-09-05 12:03:22 +08:00
parameters = "led"
def output(self, n):
print("Received: "+str(n))
2014-07-06 04:48:27 +08:00
2014-09-05 12:03:22 +08:00
def get_max(self):
return int(input("Maximum: "))
2014-07-08 01:14:39 +08:00
2014-09-05 12:03:22 +08:00
@kernel
def run(self):
self.led.set(1)
m = self.get_max()
2014-09-10 16:06:27 +08:00
for x in range(1, m):
2014-09-05 12:03:22 +08:00
d = 2
prime = True
while d*d <= x:
if x % d == 0:
prime = False
2014-09-10 16:16:12 +08:00
break
2014-09-05 12:03:22 +08:00
d += 1
if prime:
self.output(x)
self.led.set(0)
2014-07-08 01:14:39 +08:00
2014-07-06 04:48:27 +08:00
if __name__ == "__main__":
2014-09-05 12:03:22 +08:00
with corecom_serial.CoreCom() as com:
coredev = core.Core(com)
exp = CompilerTest(
core=coredev,
led=gpio_core.GPIOOut(core=coredev, channel=0)
)
exp.run()