A correspondent asks: "I am a middle school teacher. I teach my students to program Arduinos. How hard would it be to add the Arduino programming language to Code Runner?"
The Arduino language (so-called "AVR_C") is essentially GNU C++, which is built in to CodeRunner. The differences are in the linking and libraries. You could teach basic programming concepts out of the box, but asking for Arduino-specific code is a lot harder. You would need to have test implementations ("mocks") of any Arduino library classes and functions that the student code requires. This could become almost arbitrarily complex if you wanted to specify the particular peripherals being used and the wiring diagram in order to check that the code worked with that hardware configuration.
But it all depends what sort of question you wanted to ask. Here's a simple example (based on this tutorial) showing what you can do without too much effort.
That question uses a customised C++ program question with the following template:
#include <stdio.h> #define LED_BUILTIN 13 #define LOW 0 #define HIGH 1 #define OUTPUT 1 int time = 0; // msecs void pinMode(int pin, int mode) { if (pin != LED_BUILTIN) { printf(" pinMode: setting unknown pin %d\n", pin); } else if (mode != OUTPUT) { printf(" pinMode: setting mode to unknown value\n"); } else { printf(" pinMode: pin %d set as an output\n", LED_BUILTIN); } } void delay(int deltaMillisecs) { time += deltaMillisecs; } void digitalWrite(int pin, int state) { if (pin != LED_BUILTIN) { printf(" digitalWrite: setting unknown pin %d\n", pin); } else if (state != LOW && state != HIGH) { printf(" digitalWrite: setting pin to illegal value %d\n", state); } else { printf(" digitalWrite: pin %d set to %d at time %d msecs\n", pin, state, time); } } {{ STUDENT_ANSWER }} int main() { printf("Setting up:\n"); setup(); printf("Looping:\n"); for (int i = 1; i <= 5; i++) { // 5 iterations should be enough loop(); } }
However, this works only if the student uses the expected constants and library functions; if they get "creative" (e.g. they googled, found some random code they didn't understand, and pasted it in) their answer won't be accepted. You may or may not care. If you do care, and certainly when you start asking more advanced questions, you'll have to provide mock implementations for lots more of the Arduino library constants, functions and classes.
Richard