2014-08-13 18:30:57 +08:00
|
|
|
from artiq.language.core import AutoContext, kernel
|
2014-07-16 01:20:13 +08:00
|
|
|
from artiq.devices import corecom_serial, core, gpio_core
|
2014-07-06 04:48:27 +08:00
|
|
|
|
2014-08-13 18:30:57 +08:00
|
|
|
class CompilerTest(AutoContext):
|
2014-07-11 07:12:40 +08:00
|
|
|
parameters = "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
|
2014-08-18 23:16:02 +08:00
|
|
|
prime = True
|
2014-07-07 00:29:02 +08:00
|
|
|
while d*d <= x:
|
|
|
|
if x % d == 0:
|
2014-08-18 23:16:02 +08:00
|
|
|
prime = False
|
2014-08-18 23:17:23 +08:00
|
|
|
d += 1
|
2014-08-18 23:16:02 +08:00
|
|
|
if prime:
|
2014-07-08 01:14:39 +08:00
|
|
|
self.output(x)
|
2014-08-18 23:17:23 +08:00
|
|
|
x += 1
|
2014-07-07 00:29:02 +08:00
|
|
|
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:
|
2014-07-16 01:20:13 +08:00
|
|
|
coredev = core.Core(com)
|
2014-07-06 04:53:48 +08:00
|
|
|
exp = CompilerTest(
|
|
|
|
core=coredev,
|
2014-08-09 14:32:10 +08:00
|
|
|
led=gpio_core.GPIOOut(core=coredev, channel=0)
|
2014-07-06 04:53:48 +08:00
|
|
|
)
|
|
|
|
exp.run()
|