2014-07-11 00:13:37 +08:00
|
|
|
from artiq.language.core import MPO, kernel
|
2014-07-06 04:48:27 +08:00
|
|
|
from artiq.devices import corecom_serial, runtime, core, gpio_core
|
|
|
|
|
2014-07-10 21:29:22 +08:00
|
|
|
class CompilerTest(MPO):
|
2014-07-10 21:38:51 +08:00
|
|
|
channels = "led"
|
2014-07-06 04:48:27 +08:00
|
|
|
|
2014-07-08 01:14:39 +08:00
|
|
|
def output(self, n):
|
|
|
|
print("Received: "+str(n))
|
|
|
|
|
|
|
|
def get_max(self):
|
|
|
|
return int(input("Maximum: "))
|
|
|
|
|
2014-07-06 04:48:27 +08:00
|
|
|
@kernel
|
|
|
|
def run(self):
|
|
|
|
self.led.set(1)
|
2014-07-07 00:29:02 +08:00
|
|
|
x = 1
|
2014-07-08 01:14:39 +08:00
|
|
|
m = self.get_max()
|
|
|
|
while x < m:
|
2014-07-07 00:29:02 +08:00
|
|
|
d = 2
|
|
|
|
prime = 1
|
|
|
|
while d*d <= x:
|
|
|
|
if x % d == 0:
|
|
|
|
prime = 0
|
|
|
|
d = d + 1
|
|
|
|
if prime == 1:
|
2014-07-08 01:14:39 +08:00
|
|
|
self.output(x)
|
2014-07-07 00:29:02 +08:00
|
|
|
x = x + 1
|
|
|
|
self.led.set(0)
|
2014-07-06 04:48:27 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2014-07-06 04:53:48 +08:00
|
|
|
with corecom_serial.CoreCom() as com:
|
|
|
|
coredev = core.Core(runtime.Environment(), com)
|
|
|
|
exp = CompilerTest(
|
|
|
|
core=coredev,
|
|
|
|
led=gpio_core.GPIOOut(coredev, 0)
|
|
|
|
)
|
|
|
|
exp.run()
|