I'm new to RPI and to Python 3 and I have a problem running this code on a RPI 2.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
redled = 4
greenled = 26
GPIO.setup(redled, GPIO.OUT)
GPIO.setup(greenled, GPIO.OUT)
count = 1
while count < 100000:
GPIO.output(redled, 1)
GPIO.output(greenled, 1)
time.sleep(.1)
GPIO.output(redled, 0)
GPIO.output(greenled, 0)
time.sleep(.1)
count = count + 1
GPIO.cleanup()
I get this error.
Traceback (most recent call last): File "/home/pi/testreactionrepeat.py", line 7, in GPIO.setup(redled, GPIO.OUT) RuntimeError: No access to /dev/mem. Try running as root!
I was using this code with no problems a couple of days ago and can't figure out what I'm doing wrong now. I found a similar problem and the answer was to run "sudo su" but I get a syntax error when I try that.