The html code in this Processing sketch is interfering with the html tags for preformatted code.
Please see the source code of this page for the original .ino sketch.
/*
Beta Spectrum Web Server
Context: Arduino Due
Input pulses can be attached to any digital pin (max 3.3 V)
*/
#include
#include
#include
EthernetServer server(80);
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0D, 0xD5, 0x91 };
IPAddress gateway(194,47,126,33);
IPAddress subnet(255,255,255,224);
IPAddress ip(194,47,126,55);
const int inputLength = 16;
const int typeLength = 6;
const long checkInterval = 10000;
const int distanceAddress = 10;
char inputString[inputLength];
char requestTypeString[inputLength];
int nextChar = 0;
const int fileStringLength = 16;
char fileString[fileStringLength];
long resetTime;
int voltage = -100;
int inputPin = 22;
volatile int betaCounts = 0; // variable must not be stored in a register
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
void setup()
{
Serial.begin(9600);
Serial.print("Initializing Ethernet connection... ");
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
analogWriteResolution(12);
analogWrite(DAC0, voltage);
analogWrite(DAC1, 0);
resetTime = millis();
betaCounts = 0;
pinMode(inputPin, INPUT);
attachInterrupt(inputPin, incrementCounts, RISING);
}
void incrementCounts() { // interrupt service routine
betaCounts++;
}
void loop()
{
String fileName = "";
char inChar = 0;
int requestType = 0;
int requestedFileLength = 0;
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("Got a client");
TextFinder finder(client);
while (client.connected()) {
if (client.available()) {
// look for whatever becomes before the / (GET or POST)
if(finder.getString("","/",requestTypeString,typeLength)) {
Serial.print(requestTypeString);
Serial.println(typeLength);
}
if(String(requestTypeString).startsWith("GET")) {
makeGETResponse(client);
}
if(String(requestTypeString).startsWith("POST")) {
finder.find("\n\r"); // skip the rest
if(finder.find("millivolts")) {
voltage = finder.getValue('=') % 4096; // modulo for DAC range
}
makePOSTResponse(client);
}
// give the client time to receive the data
delay(1);
Serial.println("Closing the connection.");
client.stop();
}
}
}
}
void makePOSTResponse(EthernetClient thisClient) {
thisClient.print("HTTP/1.1 200 OK\n");
thisClient.print("Content-Type: text/html\n\n");
thisClient.print("");
thisClient.print("Arduino experiment server \n");
// set up the body background color tag:
thisClient.print(" \n");
thisClient.print("Beta spectrum experiment
\n");
thisClient.print("Voltage setting changed to ");
thisClient.print(voltage);
if (voltage < 0)
{
analogWrite(DAC0, 0);
analogWrite(DAC1, -voltage);
}
else
{
analogWrite(DAC1, 0);
analogWrite(DAC0, voltage);
}
delay(10);
betaCounts = 0;
resetTime = millis();
thisClient.print("
Counter and timer reset; ");
thisClient.print("return to controls
");
thisClient.println("");
}
void makeGETResponse(EthernetClient thisClient) {
float time;
time=(millis()-resetTime)/1000.0;
thisClient.print("HTTP/1.1 200 OK\n");
thisClient.print("Content-Type: text/html\n\n");
thisClient.print("");
thisClient.print("Arduino experiment server \n");
// set up the body background color tag:
thisClient.print(" \n");
thisClient.print("Beta rate experiment
");
thisClient.print(" \n");
thisClient.print(" \n");
// close the page:
thisClient.println("\n");
delay(1);
}