So I'm not sure whether this is in the right category, but I suppose it is to do with troubleshooting as I'm 99% certain it has nothing to do with the code for reasons I'll get into.
I'm using a raspberry pi pico.
I'm getting the compilation error 'rp2040' was not declared in this scope while using the raspberry pi pico to run multiple cores. I'm pretty new to this particular aspect of programming but the code is an example given to us by our lecturer so it should work fine.
I've asked classmates and they've all said they had no issues running the example code, nor did they have any issues implementing multicore processing so it must have something to do with missing libraries. I've reinstalled the IDE and recently upgraded to 2.0.1 with no success.
// traffic_lights_5
#include "sub.h"
// global variables
uint8_t state=0, oldstate;
uint32_t watch = millis();
#include "second.h"
void loop() {
// put your main code here, to run repeatedly:
switch (state) {
case 0:
r();
if ((millis()-watch) > 1000 ) {
watch = millis(); state = 1;
}
break;
case 1:
ry();
if ((millis()-watch) > 1000 ) {
watch = millis(); state = 2;
}
break;
case 2:
g();
if ((millis()-watch) > 1000 ) {
watch = millis(); state = 3;
}
break;
case 3:
y();
if ((millis()-watch) > 1000 ) {
watch = millis(); state = 0;
}
break;
case 4:
r();
if ((millis()-watch) > 3000 ) {
watch = millis(); state = oldstate;
}
break;
}
if ( rp2040.fifo.available() ) {
uint32_t dummy; // received values
while ( rp2040.fifo.available() ) // clear fifo
rp2040.fifo.pop_nb(&dummy);
oldstate = state;
state = 4;
}
}
Inside second.h subroutine...
void loop1() {
if ( !digitalRead(20) ) {
rp2040.fifo.push_nb(1);
delay(10000);
}
}
And inside the sub.h subroutine
#define R_led 8
#define Y_led 7
#define G_led 6
void setup() {
// put your setup code here, to run once:
pinMode(R_led,OUTPUT);
pinMode(Y_led,OUTPUT);
pinMode(G_led,OUTPUT);
//attachInterrupt(digitalPinToInterrupt(20),isr20,FALLING);
}
void r(void) { // after y
analogWrite(G_led,0);
analogWrite(Y_led,0);
analogWrite(R_led,5);
}
void ry(void) { // after r
analogWrite(G_led,0);
analogWrite(Y_led,20);
analogWrite(R_led,5);
}
void g(void) { // after ry
analogWrite(G_led,255);
analogWrite(Y_led,0);
analogWrite(R_led,0);
}
void y(void) { // after g
analogWrite(G_led,0);
analogWrite(Y_led,20);
analogWrite(R_led,0);
}
Completely at a loss at this point. Any help would be greatly appreciated.




