Copied in Stackduino 1 sketch to adapt