Integration of square wave
If your square wave has a mean of zero (this is important!), then a simple accumulator can do the job. Its operation is described by

$$y[n]=x[n]+y[n-1]$$

where $x[n]$ is the input (square wave) and $y[n]$ is the output (triangular wave).

This is a simple Matlab/Octave script showing how it works:


sq = [1,-1,1,-1,1,-1,1,-1]'*ones(1,5);
sq = sq'(:);                 % a few periods of a square wave
tr = filter(1,[1,-1],sq);    % filtered by accumulator
% plot
subplot(2,1,1),stem(sq)
subplot(2,1,2),stem(tr)